Log4net app.config with console and file logging

Code,Final University Project — Mark @ 6:31 pm

Here is a quick example .config of log4net that does basic logging to the console and to a text file. I found a great tutorial outlining the config here but it didnt have a full example anywhere from what I found.


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <userSettings>
       <!—My project application settings -->
        </Client.Properties.Settings>
        <log4net>
          <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
            <target value="Console.Error" />
            <layout type="log4net.Layout.SimpleLayout" />
          </appender>
          <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="log.txt" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="10" />
            <maximumFileSize value="1MB" />
            <staticLogFileName value="true" />
            <layout type="log4net.Layout.SimpleLayout" />
          </appender>
          <root>
            <level value="ALL" />
            <appender-ref ref="ConsoleAppender" />
            <appender-ref ref="RollingFileAppender" />
          </root>
        </log4net>
    </userSettings>
<!—My WCF binding settings were in here -->
</configuration>
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2016 Mark Stahler – Blog | powered by WordPress with Barecity