Don’t reinvent the wheel

Because while roll-your-own is fun, it’s also annoying and counter-productive.

 

 

http://csharp-source.net/open-source/logging - a survey of some logging frameworks
O’Reilly: Using log4net - a 2003 article, so not quite up-to-date
http://sometechcompany.com/TechBlog/Log4NetReview.aspx

 

http://visuallogparser.codeplex.com/

 

 

  Log4Net

From the Apache foundation

 

http://logging.apache.org/log4net/
log4net home (@ apache.org)

 

https://logging.apache.org/log4net/release/manual/introduction.html

 

FAQ

 

 

Log4Net with VB.Net - I mostly use C#, and the VB setup in 2.0 was throwing me off, a bit

 

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;

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();
            XmlConfigurator.Configure();
            _log.Info("Class Initialized");
        }

    }
}

 

  NLog

http://nlog.codeplex.com/ - simple to set up and output to a file.
http://www.codeproject.com/KB/trace/nlog.aspx

 

 

I tried working with log4Net via the tutorials and several online review/tutorial/ex(s)amples. But there were just far more options than I wanted, and it was dumping to the console, not to a file. If I’m looking for a logger — I want it to log, not to write some pixels in the air that vanish when the app fatally crashes. And if I have to spend hours digging through docs and demos just to find that minimal functionality — something’s wrong.

 

Tail for win32

Not really a logger, but a good way to read your log files.
Tail for Win32

 

 

See Also