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. 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). The config file is below:
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
[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?
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.
This will fix your problem:
[assembly: log4net.Config.XmlConfigurator()]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.