C#控制台应用程序的记录器应用程序 [英] Logger application for c# console application

查看:80
本文介绍了C#控制台应用程序的记录器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是职业生涯中第一次设计控制台应用程序.该控制台应用程序是一个引擎,它将在每晚的特定时间执行任务.我将使用Windows Task Scheduler来调度此应用程序.

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.

现在,我需要记录此任务的每个步骤.我不确定哪种记录器最适合这种应用程序.该日志消息可以存储到数据库,xml或平面文件中.

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?

推荐答案

尝试 NLog 基本上是从Log4j到.NET.您可以以编程方式或通过.xml文件对其进行配置.第二个选项很方便,因为您不必每次都要更改日志记录选项时都重新编译项目.在代码中,通用用法看起来像这样.

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

这篇关于C#控制台应用程序的记录器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆