Note that there are some explanatory texts on larger screens.

plurals
  1. POlog4net fileappender not creating log-file.txt in Outlook ThisAddIn.cs
    text
    copied!<p>I can't see what is wrong here. I just want to get log4net writing to a log file with my Outlook AddIn. I have the following in my <strong>app.config</strong> file:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/&gt; &lt;/configSections&gt; &lt;log4net&gt; &lt;appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" &gt; &lt;param name="File" value="log-file.txt" /&gt; &lt;param name="AppendToFile" value="true" /&gt; &lt;rollingStyle value="Size" /&gt; &lt;maxSizeRollBackups value="10" /&gt; &lt;maximumFileSize value="10MB" /&gt; &lt;staticLogFileName value="true" /&gt; &lt;layout type="log4net.Layout.PatternLayout"&gt; &lt;param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" /&gt; &lt;/layout&gt; &lt;/appender&gt; &lt;root&gt; &lt;level value="DEBUG" /&gt; &lt;appender-ref ref="LogFileAppender" /&gt; &lt;/root&gt; &lt;/log4net&gt; &lt;/configuration&gt; </code></pre> <p>Here are the relevant statements in my startup class, ThisAddIn.cs (comments show variations I have tried):</p> <pre><code>//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"); } </code></pre> <p>In my research of this, it should write to a file called log-file.txt in my project/bin/Debug folder but I see nothing created. When I step into the code with the Debugger the methods of the log object appear to work without complaint. I also tried the following absolute specification for the file with the same lack of results:</p> <pre class="lang-xml prettyprint-override"><code>&lt;param name="File" value="c:\\try\\logger\\log-file.txt" /&gt; </code></pre> <p>Can someone spot my mistake? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload