[英]Log4Net not creating .txt file?
This is my first attempt at logging, and I have researched similar questions, but cant seem to figure out my situation, probably because I am not getting any errors to go off of. 这是我第一次尝试进行日志记录,并且我已经研究了类似的问题,但是似乎无法弄清楚我的处境,可能是因为我没有遇到任何错误。
I am trying to use Log4Net to simply create a .txt file. 我正在尝试使用Log4Net来简单地创建一个.txt文件。 I do not have a web.config or app.config, so I created my own config file to setup Log4Net(Through research, I found that I should be able to do this).
我没有web.config或app.config,因此我创建了自己的配置文件来设置Log4Net(通过研究,我发现我应该能够这样做)。 The config file is below:
配置文件如下:
Log4Net.config Log4Net.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\myFolder\TestLog.txt" />//******Nothing Is Being Created Here****
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
</configuration>
In my AssemblyInfo.cs 在我的AssemblyInfo.cs中
[assembly: log4net.Config.XmlConfigurator(ConfigFile =
"Log4Net.config", Watch = true)]
And the call to the logger 并致电记录器
....
private static readonly ILog logger = LogManager.GetLogger("ExportLogger");
....
log4net.Config.XmlConfigurator.Configure();//I know this shouldnt be done here, just testing
logger.Debug("Successfully logged something");
The above code all runs without error, so I am not sure where my mistake is. 上面的代码都没有错误地运行,所以我不确定我的错误在哪里。 I suspect I have the configuration setup incorrectly.
我怀疑我的配置设置不正确。 Can anyone see what I am doing wrong and why there is no creation of the .txt file?
谁能看到我在做错什么,为什么没有创建.txt文件?
The error in your attribute: 您的属性中的错误:
[assembly: log4net.Config.XmlConfigurator(ConfigFile =
"Log4Net.config", Watch = true)]
You define the configuration file, but you are using the app.config for the configuration. 您定义了配置文件,但是您正在使用app.config进行配置。
This will fix your problem: 这将解决您的问题:
[assembly: log4net.Config.XmlConfigurator()]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.