C# 控制台应用程序的记录器应用程序

发布于 2024-09-14 01:45:25 字数 187 浏览 2 评论 0原文

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

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

您能为这种情况提供最佳记录器应用程序的建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ˉ厌 2024-09-21 01:45:25

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

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

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"); 
    }
}
浮华 2024-09-21 01:45:25

我们通常使用 log4net 来记录我当前正在维护的应用程序中的所有日志记录。效果很好。然后我们有脚本每天将日志压缩为 zip 文件以节省磁盘空间(因为某些应用程序的日志记录非常详细)。

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

冰之心 2024-09-21 01:45:25

.NET 上最常见的日志框架是 Log4NetNLog,尽管还有其他的。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文