Skip to content

Instantly share code, notes, and snippets.

@mazhar-ansari-ardeh
Last active November 15, 2017 07:33
Show Gist options
  • Save mazhar-ansari-ardeh/48216e45ad0b920a7b0d973b35679935 to your computer and use it in GitHub Desktop.
Save mazhar-ansari-ardeh/48216e45ad0b920a7b0d973b35679935 to your computer and use it in GitHub Desktop.
A sample config file that contains the most basic structure of a typical config file.
<!-- Save this file to as SampleLog4netConfigfile.config and load it with the following code inside the AssemblyInfo.cs file
of the project:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "SampleLog4netConfigfile.config", Watch = true)]
After this, log4net library can be used inside the project. For example, logger variables can be defined as private static
variables:
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-->
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<root>
<level value="DEBUG"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logfile.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="5"/>
<maximumFileSize value="10MB"/>
<staticLogFileName value="true"/>
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/>
</layout>
</appender>
</log4net>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment