Skip to content

Instantly share code, notes, and snippets.

@xtrmstep
Created October 10, 2017 14:54
Show Gist options
  • Save xtrmstep/b02a6da3f54aa6d40ed62e50096e10d6 to your computer and use it in GitHub Desktop.
Save xtrmstep/b02a6da3f54aa6d40ed62e50096e10d6 to your computer and use it in GitHub Desktop.
log4net snippets
// variable declaration
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// You have several options to make it alive
// 1) AssemblyInfo.cs
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
// 2) manual kick in the beginning of program execution
XmlConfigurator.Configure();
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<log4net>
<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file value="d:\logs\data.log" />
<rollingStyle value="Once" />
<maxSizeRollBackups value="10" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline%exception" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment