Skip to content

Instantly share code, notes, and snippets.

@MichaelPaulukonis
Created August 29, 2013 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelPaulukonis/6381986 to your computer and use it in GitHub Desktop.
Save MichaelPaulukonis/6381986 to your computer and use it in GitHub Desktop.
log4net simple configuration
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false"/>
</configSections>
<log4net>
<!-- Define some output appenders -->
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="filename.log"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="5"/>
<maximumFileSize value="5MB"/>
<staticLogFileName value="true"/>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="FATAL" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>
</configuration>
// using log4net.Config; no need for a reference -- fully qualified in the single instance, below
namespace MyNameSpace
{
public class MyClass
{
// setup-info is in .config
private static readonly log4net.ILog _log = log4net.LogManager.GetLogger
(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public MyClass()
{
InitializeComponent();
log4net.Config.XmlConfigurator.Configure();
_log.Info("Class Initialized");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment