Pan*_*cus 4 .net logging enterprise-library app-config web-config
我正在尝试将Enterprise .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();
}
Run Code Online (Sandbox Code Playgroud)
我没有收到日志消息,而是在事件日志中遇到错误:
消息:类别“ 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>
Run Code Online (Sandbox Code Playgroud)
我尝试将其设置logWarningsWhenNoCategoriesMatch为false,但这只是使警告静音-不能使日志记录正常工作。
我也尝试过摆脱<notProcessed switchValue="All" .../>特殊的来源,但这似乎也没有任何作用。
有人知道是否有办法使它起作用吗?谢谢!
小智 5
'notProcessed'特殊源将匹配与类别源不匹配的所有条目-因此您可以使用它来捕获它们。这里有更多信息:https : //entlib.codeplex.com/discussions/215189
<notProcessed switchValue="All" name="Unprocessed Category"/>
<listeners>
<add name="Rolling Flat File Trace Listener Unprocessed"/>
</listeners>
</notProcessed>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16131 次 |
| 最近记录: |