【发布时间】:2011-07-19 00:07:07
【问题描述】:
我正在尝试将Common Infrastructure Libraries for .NET (Common.Logging) 与 Enterprise Library 4.1 的日志记录应用程序块一起使用。根据docs,这是支持的。
我遇到的问题是,当我尝试记录一些东西时,就像这样(在这个例子中,我在一个 ASP.NET MVC 应用程序中):
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
ILog log = LogManager.GetCurrentClassLogger();
log.Info("Hello world!");
return View();
}
我没有收到日志消息,而是在我的事件日志中收到错误:
消息:“TestApp.Controllers.HomeController”类别没有显式映射。
嗯,Common.Logging 中似乎没有任何选项来设置默认类别,我不知道如何配置 LoggingConfiguration 以接受任何类别,即使它没有定义。
这是我的 LoggingConfiguration 的 sn-p:
<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" .../> 特殊来源,但这似乎也没有任何效果。
有人知道是否有办法让它工作吗?谢谢!
【问题讨论】:
标签: .net logging web-config app-config enterprise-library