views:

60

answers:

3

I'm designing a console application for the first time in my career. This console application is an engine which will do a task every night at particular time. I'm going to schedule this application using windows task scheduler.

Now I need to log every step in this task. I'm not sure what logger best suits for this kind of application. This log messages may be stored to a database, xml or a flat file.

Can you give your suggestions for best logger application for this kind of scenario?

+3  A: 

We typically use log4net for all logging in the applications that I am currently part of maintaining. Works quite well. Then we have scripts that compresses the logs on a daily basis into zip files to save disk space (since some of the applications are quite verbose in their logging).

Fredrik Mörk
Is log4net compatible with .net 4.0?
JPReddy
@JayaprakashReddy: I haven't tried it out myself, but it would surprise me if there were any major issues. There is a discussion on the topic here: http://stackoverflow.com/questions/1866735/log4net-and-net-4-0
Fredrik Mörk
log4net has a dependency on System.Web, so you can't use it in a .NET 4 Client Profile project. An issue has been raised in their JIRA system but there doesn't seem to be much movement on the project these days - the last release was over 2 years ago
Phil Devaney
+1 for log4net, fantastic kit.
AndyC
+2  A: 

Try NLog it is basically port of Log4j to .NET. You can configure it programmatically or through .xml file. The second option is handy because you don't have to recompile your project every time you want to change logging options. In code common use would look like.

class MyClass
{
    private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

    public void MyMethod()
    {
        // available logging levels TRACE,INFO,DEBUG,WARN,ERROR, FATAL
        Logger.Debug("Debug message"); 
    }
}
jethro
@jethro: Are there any tools available for viewing the log messages written to file from NLog? How do you view these log files?
JPReddy
depends on the output. Nlog can write logs to a tcp server, database, text files, etc etc.
jgauffin
basically `tail -f` :). But you can try [baretail](http://www.baremetalsoft.com/baretail/) it can parse any log file or apache tool called [chainsaw](http://logging.apache.org/chainsaw/index.html) designed for log4j
jethro
A: 

The most common logging frameworks on .NET are Log4Net and NLog, although there are others.

See also this question.

Paul Ruane