【问题标题】:DB logging using Fluent Interface使用 Fluent Interface 进行数据库日志记录
【发布时间】:2011-10-31 10:27:56
【问题描述】:

我正在使用企业库 5.0。使用流畅的界面,我能够为基于文件和基于事件的日志记录配置跟踪列表器。有什么方法可以为数据库侦听器配置它。我的想法是不使用任何特定于 Logging 配置的外部配置文件。

我使用以下,我能够登录一个 flatFile,事件查看器。当我尝试使用 DBListner 登录时,我没有收到任何错误消息,但也没有记录该消息。有人能解释一下吗?

.SendTo.RollingFile("Flat File Trace Listener")
        .ToFile("Trace.log")
        .WithHeader("----------------------")
        .FormatWith(new FormatterBuilder()
        .TextFormatterNamed("Text Formatter")
        .UsingTemplate("Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title:{title}{newline}Machine: {machine}{newline}Application Domain: {appDomain}{newline}Process Id: {processId}{newline}Process Name: {processName}{newline}Win32 Thread Id: {win32ThreadId}{newline}Thread Name: {threadName}{newline}Extended Properties: {dictionary({key} - {value}{newline})}"))

        .SendTo.EventLog("Formatted EventLog TraceListener")
        .FormatWithSharedFormatter("Text Formatter")
        .ToLog("Application")
        .LogToCategoryNamed("General").WithOptions.SetAsDefaultCategory()

        .SendTo.Database("Formatted Database TraceListener")
        .UseDatabase("MyDatabase")            
        .FormatWith(new FormatterBuilder().TextFormatterNamed("TextFormat"))
        .WithWriteLogStoredProcedure("WriteLog")
        .WithAddCategoryStoredProcedure ("AddCategory")
        .LogToCategoryNamed("DBLogger").WithOptions.SetAsDefaultCategory();

        builder.ConfigureData()
        .ForDatabaseNamed("MyDatabase")
        .ThatIs.ASqlDatabase()
        .WithConnectionString("Data Source=.\SQLExpress;Initial Catalog=Logging;Integrated ecurity=True;")
        .AsDefault();

【问题讨论】:

    标签: enterprise-library-5


    【解决方案1】:

    LogToCategoryNamed 方法必须先出现。像这样的:

    .LogToCategoryNamed("DBLogger")
        .SendTo.Database("Formatted Database TraceListener")
            .UseDatabase("MyDatabase")
            .FormatWith(new FormatterBuilder().TextFormatterNamed("Text Formatter"));
    

    可以在here 找到有关使用 fluent API 进行日志记录的文档。

    【讨论】:

      猜你喜欢
      • 2011-03-06
      • 2012-02-08
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 2012-05-11
      • 2011-03-01
      • 1970-01-01
      相关资源
      最近更新 更多