Created
August 29, 2013 18:53
-
-
Save MichaelPaulukonis/6381986 to your computer and use it in GitHub Desktop.
log4net simple configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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