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?
<configuration>and<configSections>elements, as they are only applicable to app/web.config files. Also use the overload oflog4net.Config.XmlConfigurator.Configure()that lets you pass in that file. You can checkLogManager.GetRepository().Configuredto see if the configuration has been loaded. If it still doesn't work, add a trace listener to the debug output - stuartd