简体   繁体   English

如何使用EL 6.0记录C#控制台应用程序

[英]How to do logging of C# Console application using EL 6.0

Can any one let me know how to implement logging with Enterprise Library 6.0 in C#. 谁能让我知道如何在C#中使用Enterprise Library 6.0实现日志记录。 I want to do logging in Database, if it is available otherwise log the exceptions , information, messages into LOG file. 我想在数据库中进行记录,如果可用,否则将异常,信息,消息记录到LOG文件中。
Can anyone tell me How to implement logging into Db, otherwise log in file dynamically. 谁能告诉我如何实现登录Db,否则动态登录文件。
I will have both logging DB and file config changes in App.config / Web.config . 我将在App.config / Web.config同时记录日志数据库和文件配置更改。
So please help me on this how to implement logging dynamically based on runtime value: If Db is available and accessible, then log, otherwise if DB is not accessible, then log to Log-file or event-viewer. 因此,请帮助我了解如何基于运行时值动态实现日志记录: 如果Db可用且可访问,则进行日志记录,否则,如果DB不可访问,则记录至日志文件或事件查看器。

The new version 6 makes comprehensive use of the factory pattern, hence you need to set the logger up differently in version 6: 新版本6充分利用了工厂模式,因此您需要在版本6中对记录器进行不同的设置:

  • Try the following: 请尝试以下操作:

     IConfigurationSource configsrc = ConfigurationSourceFactory.Create(); LogWriterFactory logWriterFactory = new LogWriterFactory(configsrc); Logger.SetLogWriter(logWriterFactory.Create()); Logger.Write("logtest", "General"); 
  • Your description of your database logging requirements isn't quite clear, but I think these Code examples and links should be what you are looking for. 您对数据库日志记录要求的描述还不太清楚,但是我认为这些代码示例和链接应该是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM