企业库日志应用程序块无法写入数据库

时间:2013-08-01 07:24:32

标签: c# exception-handling enterprise-library enterprise-library-5 tracelistener

在我的应用程序中,我使用Enterprise库日志记录应用程序块来记录DB的异常。另外,我使用流畅的API来配置日志记录应用程序块。

我注意到的事情:

  1. 当我没有使用Fluent API且数据库记录失败时,它将异常记录到Windows事件日志。(版本5.0)
  2. 但是当我使用它时(Fluent API),如果数据库出现故障,即使在windown事件日志中也没有记录异常。
  3. 我的问题:

    1. 是企业库日志应用程序块的正常行为吗?
    2. 有没有办法使用流畅的API我可以获得我没有它的功能,意思是(如果数据库记录失败登录到Windows事件日志)。
    3. 如有任何差异,请随时提出建议。 : - )

1 个答案:

答案 0 :(得分:2)

确切的语法取决于您现有的配置。假设您没有配置要使用的跟踪侦听器或格式化程序:

configurationSourceBuilder
    .ConfigureLogging()
    .SpecialSources.LoggingErrorsAndWarningsCategory
    .SendTo.EventLog("Event Log Listener")
    .FormatWith(new FormatterBuilder().TextFormatterNamed("Text Formatter"));

如果您已经配置了要使用的事件日志跟踪侦听器(在此示例中名为“Event Log Listener”):

configurationSourceBuilder
    .ConfigureLogging()
    .SpecialSources.LoggingErrorsAndWarningsCategory
    .SendTo.SharedListenerNamed("Event Log Listener");

如果您已经配置了要使用的日志格式化程序(在此示例中名为“Text Formatter”):

configurationSourceBuilder
    .ConfigureLogging()
    .SpecialSources.LoggingErrorsAndWarningsCategory
    .SendTo.EventLog("Event Log Listener")
    .FormatWithSharedFormatter("Text Formatter");
相关问题