Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Heres example for log4net:<br /></p> <ol> <li>Create a new console project called Log4NetTest<br /></li> <li>Add log4net [1.2.13] nuget package into project<br /></li> <li><p>Write following program:<br /></p> <pre><code>using System.Threading.Tasks; using log4net; using System.Text; using System.CollectionsGeneric; using System; namespace Log4NetTest { class Program { private static readonly ILog _logger = LogManager.GetLogger("testApp.LoggingExample"); static void Main(string[] args) { // Configure from App.config. This is marked as obsolete so you can also add config into separate config file // and use log4net.Config.XmlConfigurator method to configure from xml file. log4net.Config.DOMConfigurator.Configure(); _logger.Debug("Shows only at debug"); _logger.Warn("Shows only at warn"); _logger.Error("Shows only at error"); Console.ReadKey(); } } } </code></pre></li> <li><p>Change your app.config to following:<br /></p> <pre><code>&lt;!-- language: xml --&gt; &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;startup&gt; &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt; &lt;/startup&gt; &lt;log4net debug="false"&gt; &lt;appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net" &gt; &lt;param name="File" value="myLog.log" /&gt; &lt;param name="AppendToFile" value="true" /&gt; &lt;layout type="log4net.Layout.PatternLayout,log4net"&gt; &lt;param name="ConversionPattern" value="%date [%thread] %-5level %logger %ndc - %message%newline" /&gt; &lt;/layout&gt; &lt;/appender&gt; &lt;root&gt; &lt;priority value="ALL" /&gt; &lt;appender-ref ref="LogFileAppender" /&gt; &lt;/root&gt; &lt;category name="testApp.LoggingExample"&gt; &lt;priority value="ALL" /&gt; &lt;/category&gt; &lt;/log4net&gt; &lt;/configuration&gt; </code></pre></li> </ol> <p>5.Run application and you should find following file from bin\Debug folder:</p> <pre><code>2013-12-13 13:27:27,252 [8] DEBUG testApp.LoggingExample (null) - Shows only at debug 2013-12-13 13:27:27,280 [8] WARN testApp.LoggingExample (null) - Shows only at warn 2013-12-13 13:27:27,282 [8] ERROR testApp.LoggingExample (null) - Shows only at error </code></pre>
 

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