log4net 缺少什么 - 未创建日志文件
我试图在 VB.NET 应用程序中使用 log4net,但由于某种未知原因,它没有创建日志文件。
这是我的 app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:\log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
这是应用程序代码
Imports log4net
Public Class Form1
Dim log As ILog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
log.Error("test")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
log4net.Config.XmlConfigurator.Configure()
log = log4net.LogManager.GetLogger("TestThings")
End Sub
End Class
“TestThings”是 VS 项目的名称。我缺少什么?
编辑〜我以管理员身份登录,并且使用最新的 log4net.dll
I am trying to use log4net in a VB.NET app for some unknown reason it's not creating the log file.
Here is my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="c:\log-file.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
Here is the app code
Imports log4net
Public Class Form1
Dim log As ILog
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
log.Error("test")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
log4net.Config.XmlConfigurator.Configure()
log = log4net.LogManager.GetLogger("TestThings")
End Sub
End Class
"TestThings" is the name of the VS project. What am I missing?
Edit ~ I am logged in as admin and I am using the most recent log4net.dll
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
更改
为
将 log4net 也添加到
try this:
change
to
add log4net also to
尝试在滚动文件附加程序的配置中进行此更改
并在代码(表单加载或网页加载或 IOC)初始化中调用
Try this change in the config for a rolling file appender
And in your code (form load or webpage load or IOC) intialization, call