2011-10-31 108 views
0

我正在使用Enterprise library 5.0。使用流暢的界面我能夠爲基於文件和基於事件的日誌記錄配置Trace Listners。有沒有什麼辦法可以將它配置爲Database Listner。我的想法是不使用特定於日誌配置的任何外部配置文件。使用Fluent界面進行數據庫日誌記錄

我使用了以下內容,我可以登錄flatFile,Event查看器。當我嘗試使用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(); 

回答

0

LogToCategoryNamed方法必須先到達。事情是這樣的:在使用流暢的API進行記錄

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

文檔可以發現here

相關問題