我正在尝试使用.NET通用基础结构库(Common.Logging)与Enterprise Library 4.1的Logging Application Block。根据文档,这是支持的。
我遇到的问题是当我尝试记录一些东西时,就像这样(在此示例中,我在一个ASP.NET MVC应用程序中):
我尝试将
我还尝试去掉
有人知道有什么方法可以让它工作吗?谢谢!
我遇到的问题是当我尝试记录一些东西时,就像这样(在此示例中,我在一个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的一部分:
<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" .../>
特殊源,但这似乎也没有任何效果。有人知道有什么方法可以让它工作吗?谢谢!