I do not see what is wrong here. I just want log4net to write to the log file using Outlook AddIn. I have the following app.config file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> </configSections> <log4net> <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > <param name="File" value="log-file.txt" /> <param name="AppendToFile" value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} โ %m%n" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="LogFileAppender" /> </root> </log4net> </configuration>
Here are the relevant statements in my startup class, ThisAddIn.cs (comments show the options I tried):
//protected static readonly ILog log = LogManager.GetLogger("application-log"); public static readonly ILog log = LogManager.GetLogger(typeof(ThisAddIn)); private void ThisAddIn_Startup(object sender, System.EventArgs e) { //BasicConfigurator.Configure(); //XMLConfigurator.Configure(); log.Info("Application Start"); log.Warn("This is a warning message."); log.Debug("This is a debug message"); if (log.IsDebugEnabled) { log.Debug("This is another debug message"); }
In my research of this, he should write a file called log-file.txt in my project / bin / Debug folder, but I canโt see anything. When I enter the code using the debugger, the methods of the log object work without complaint. I also tried the following absolute specification for a file with the same lack of results:
<param name="File" value="c:\\try\\logger\\log-file.txt" />
Can anyone spot my mistake?
source share