我正在嘗試使用Common Infrastructure Libraries for .NET(Common.Logging)和Enterprise Library 4.1的日誌記錄應用程序塊。根據docs,這是支持的。如何配置Microsoft企業庫日誌記錄應用程序塊以處理任何日誌記錄類別?
我遇到的問題是,當我嘗試登錄的東西,像這樣(在這個例子中,我在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
爲假,但只是沉默的警告 - 它沒有記錄工作。
我也試過擺脫<notProcessed switchValue="All" .../>
特殊來源,但這似乎也沒有任何效果。
任何人都知道是否有辦法讓這個工作?謝謝!
@Tuxo - 真棒!我沒有意識到'GetLogger'會以這種方式工作 - 我的__assumption__(d'oh)是'GetLogger'會返回一個匹配給定類型的記錄器,有點像ServiceLocator模式。現在命名對我來說更有意義。謝謝!!! – Pandincus 2011-03-21 17:19:32
@Pandincus - 有一個GetLogger負載需要一個Type,這可能是您想要的。 – 2011-03-21 17:49:04