.net – 如何配置Microsoft Enterprise Library日志记录应用程序
我正在尝试将
Common Infrastructure Libraries for .NET(Common.Logging)与Enterprise Library 4.1的Logging Application Block一起使用.根据
docs,这是支持的.
我遇到的问题是,当我尝试记录某些内容时,就像这样(在本例中我是在ASP.NET MVC应用程序中): public ActionResult Index() { ViewBag.Message = "Welcome to ASP.NET MVC!"; ILog log = LogManager.GetCurrentClassLogger(); log.Info("Hello world!"); return View(); } 我没有收到日志消息,而是在事件日志中收到错误:
好吧,Common.Logging似乎没有任何选项来设置默认类别,我无法弄清楚如何配置LoggingConfiguration以接受任何类别,即使它没有定义. 这是我的LoggingConfiguration片段: <loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"> ... <categorySources> <add switchValue="All" name="General"> <listeners> <add name="Formatted EventLog TraceListener" /> <add name="Email TraceListener" /> </listeners> </add> </categorySources> <specialSources> <allEvents switchValue="All" name="All Events" /> <notProcessed switchValue="All" name="Unprocessed Category" /> <errors switchValue="All" name="Logging Errors & Warnings"> <listeners> <add name="Formatted EventLog TraceListener" /> </listeners> </errors> </specialSources> </loggingConfiguration> 我已经尝试将logWarningsWhenNoCategoriesMatch设置为false,但这只会使警告静音 – 它不会使日志记录工作. 我也尝试摆脱< notProcessed switchValue =“All”... />特殊来源,但似乎也没有任何影响. 任何人都知道是否有办法让这个工作?谢谢! 解决方法
当您调用LogManager.GetCurrentClassLogger()时,Common.Logging将使用您的调用类的类型作为类别:
public static ILog GetCurrentClassLogger() { StackFrame frame = new StackFrame(1,false); return Adapter.GetLogger(frame.GetMethod().DeclaringType); } 如果你想使用这种方法(虽然建议不要过度使用这种方法,因为它检查了StackFrame)然后,是的,你需要为你要记录的每个类创建一个类别.这将重新创建一种在Log4Net中使用的分层记录器.但这种方法并不理想,因为它不可维护. 您应该能够通过使用LogManager.GetLogger(字符串名称)重载而不是GetCurrentClassLogger来解决这个问题.看起来传入的名称将用作登录Enterprise Library的类别.因此,您可以将类别名称定义为常量,并将其传递给GetLogger方法,并让整个应用程序使用一个Enterprise Library类别. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 使用英语进行系统调用(Windows命令提示符)
- windows-phone – Windows Phone 8上的FontAwesome
- windows-server-2008 – 运行多个Hypervisor
- 10053 您的主机中的软件中止了一个已建立的连接
- windows-8 – 在启动时运行autostart_console.bat或在ConEm
- Windows Phone 8.1 cordova下拉列表无法正常工作
- 在Windows中将cp1252批量转换为utf-8
- windows – 用于删除超过X天的文件的批处理脚本(基于创建日
- 清除SQLServer日志的两种方法
- Windows Azure:将网站从www重定向到非www
- 批处理自动备份并生成日志文件
- 2018-2019-2 《网络对抗技术》Exp3免杀原理与实践
- windows-phone-7 – 如何从Windows Phone 7应用程
- dynamic-crm – 您的Microsoft Dynamics CRM经验
- windows – 如何通过PowerShell的串行控制台电缆
- windows-server-2003 – Windows 2003,IIS 6,msx
- .net – 在Windows应用程序中保存用户凭据
- .net – 如何通过webclient下载图像(jpg)并保存到
- windows+python3.6下安装fasttext+fasttext在win
- windows-server-2008 – 如何找出服务器重启的原