2016-04-25 47 views
2

我使用的EventSource登錄我的事件用EnterpriseLibrary.SemanticLogging SQL數據庫,的EventSource不寫SQL數據庫

以下是測試方法:

[TestMethod] 
    public void Log_Test() 
    { 
     var eventListener = new ObservableEventListener(); 

     var sqlListener = SqlDatabaseLog.CreateListener("Instance", CloudConfigurationManager.GetSetting("ConnectionStringTrace"), "Traces"); 
     eventListener.EnableEvents(ApplicationEventSource.Log, EventLevel.LogAlways, Keywords.All); 

     ApplicationEventSource.Log.ComponentNotLoaded("Milind", "Cheeta", "Core"); 

而且ApplicationEventSource類從EventSource的派生具有以下方法

 [Event(2, 
     Keywords = Keywords.Component, 
     Message = "Component: {2} not successfully loaded for user: {0} on machine: {1}", 
     Task = Tasks.Load, 
     Opcode = EventOpcode.Start, 
     Level = EventLevel.Error)] 
    public void ComponentNotLoaded(string userName, string machineName, string componentName) 
    { 
     WriteEvent(2, userName, machineName, componentName); 
    } 

我沒有得到錯誤,而WriteEvent但什麼都沒有日誌表跟蹤

回答

0

請發佈完整的ApplicationEventSource類。

如果改變這樣的方法:

public void ComponentNotLoaded(string userName, string machineName, string componentName) 
{ 
    if(IsEnabled()) 
     WriteEvent(2, userName, machineName, componentName); 
} 

將WriteEvent被稱爲?如果不是的話,那麼這個結構就有問題了。嘗試使用事件源分析器驗證EventSource類。

參見https://msdn.microsoft.com/en-us/library/dn774985(v=pandp.20).aspx#_Checking_an_event

此外,正常程序設置數據庫接收器是這樣的:

eventListener.LogToSqlDatabase(
       Environment.MachineName, 
       sqlConnectionString, 
      );