Logger application for c# console application

北城余情 提交于 2019-12-11 05:49:04

问题


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?


回答1:


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"); 
    }
}



回答2:


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).




回答3:


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



来源:https://stackoverflow.com/questions/3475861/logger-application-for-c-sharp-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!