Note that there are some explanatory texts on larger screens.

plurals
  1. POLog4Net/C# - Disable default logging
    text
    copied!<p>I am using log4net in a C# project, in the production environment, I want to disable all the logging, but when some fatal error occures it should log all the previous 512 messages in to a file.I have successfully configured this, and it is working fine. It logs the messages in to a file when some fatal error occures. </p> <p>But when I run it from Visual Studio, I can see all the log messages are written to the Output window, regardless of whether it is a Fatal or not. (I cant see these messages when I run from the Windows Explorer - my application is a WinForm exe and there is no Console window to see the output)</p> <p>Is there any way to disable this logging? I need my logs only in file, that too when some fatal error occures.</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;configuration&gt; &lt;log4net debug="false"&gt; &lt;appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"&gt; &lt;file value="log.txt" /&gt; &lt;appendToFile value="true" /&gt; &lt;rollingStyle value="Size" /&gt; &lt;maxSizeRollBackups value="10" /&gt; &lt;maximumFileSize value="1MB" /&gt; &lt;staticLogFileName value="true" /&gt; &lt;layout type="log4net.Layout.PatternLayout"&gt; &lt;conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /&gt; &lt;/layout&gt; &lt;/appender&gt; &lt;appender name="BufferingForwardingAppender" type="log4net.Appender.BufferingForwardingAppender" &gt; &lt;bufferSize value="512" /&gt; &lt;lossy value="true" /&gt; &lt;evaluator type="log4net.Core.LevelEvaluator"&gt; &lt;threshold value="FATAL"/&gt; &lt;/evaluator&gt; &lt;appender-ref ref="RollingFileAppender" /&gt; &lt;/appender&gt; &lt;root&gt; &lt;level value="DEBUG" /&gt; &lt;appender-ref ref="BufferingForwardingAppender" /&gt; &lt;/root&gt; &lt;/log4net&gt; &lt;/configuration&gt; </code></pre> <p>And this is how I configure it in the static initializer of Windows Forms.</p> <pre><code>static Window1() { Stream vStream = typeof(Window1).Assembly.GetManifestResourceStream("TestLogNet.log4net.config"); XmlConfigurator.Configure(vStream); BasicConfigurator.Configure(); } </code></pre> <p>And I have the logger object initialized in the constructor of WinForm</p> <pre><code>logger = LogManager.GetLogger(typeof(Window1)); </code></pre> <p>[language - C#, .NET Framework - 3.5, Visual Studio 2008, log4net 1.2.10, project type - WinForms]</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