2017-06-14 35 views
1

在某些計算機上(可能只在Windows 7和2008 R2上,但不在Windows 10上)使用SemanticLogging時出現問題。當我運行它我收到休耕輸出:SemanticLogging在EventSource的命令處理中拋出異常

Event Trace Session prefix: Microsoft-SemanticLogging-Etw 

Sink name: ConsoleEventSink 
Event sources: 
Name: 8943bf09-be18-551a-efe5-612ee62ded5e 
Performance, Level: LogAlways, MatchAnyKeyword: None 

Sink name: PerformaceSINK 
Event sources: 
Name: 8943bf09-be18-551a-efe5-612ee62ded5e 
Performance, Level: LogAlways, MatchAnyKeyword: None 

Service started. 

Press enter to end ... 
ERROR: Exception in Command Processing for EventSource Performance: Object 
reference not set to an instance of an object.; 

所有這一切發生在特定之情況:

  1. 我開始的過程,然後將事件寫入
  2. 我跑SemanticLogging-svc.exe -c
  3. 發生後幾分鐘錯誤

但是,當我改變順序,首先啓動SemanticLogging-svc.exe之後,我運行「event writer」,一切都會如何。

但是,當我設置所有第一場景描述和錯誤後,我會嘗試收集數據使用PerfView魔術發生和SemanticLogging開始收集數據。

使用PerfView我已經檢查了Microsoft-SemanticLogging-Etw源,但沒有任何內容。

SemanticLogging-svc.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://schemas.microsoft.com/practices/2013/entlib/semanticlogging/etw SemanticLogging-svc.xsd"> 
    <traceEventService /> 
    <sinks> 
    <consoleSink name="ConsoleEventSink"> 
     <sources> 
     <eventSource name="PerformanceEventSource" level="LogAlways" /> 
     </sources> 
     <customEventTextFormatter type="ServiceTelemetry.EventFormatter.CsvEventFormatter, ServiceTelemetry"/> 
    </consoleSink> 
    <rollingFlatFileSink 
     name="PerformanceEventSourceSINK" 
     fileName=".\logs\%ComputerName%_Performance.log" 
     rollFileExistsBehavior="Increment" 
     rollInterval="Midnight" 
     timeStampPattern="yyyyMMdd"> 
     <sources> 
     <eventSource name="PerformanceEventSource" level="LogAlways" /> 
     </sources> 
     <customEventTextFormatter type="ServiceTelemetry.EventFormatter.CsvEventFormatter, ServiceTelemetry"/> 
    </rollingFlatFileSink> 
    </sinks> 
</configuration> 

EventFormatter

namespace ServiceTelemetry.EventFormatter 
{ 
    public class CsvEventFormatter : IEventTextFormatter 
    { 
     public void WriteEvent(EventEntry eventEntry, TextWriter writer) 
     { 
      StringBuilder sb = new StringBuilder(); 

      for (int i = 0; i < eventEntry.Payload.Count; i++) 
      { 
       sb.AppendFormat("{0};", eventEntry.Payload[i]); 
      } 
      writer.WriteLine(sb.ToString()); 
     } 

    } 
} 

的EventSource

namespace ServiceTelemetry.EventSources 
{ 
    [EventSource(Name = "Performance")] 
    public sealed class PerformanceEventSource : EventSource 
    { 
     [Event(1, Level = EventLevel.LogAlways, Task = TaskCodes.GetResource, Opcode = OperationCodes.Compleated)] 
     public void GetResourceSuccess(string Session, string ResourceName, long ElapsedMilliseconds) 
     { 
      if (IsEnabled()) 
      { 
       WriteEvent(1, Session, ResourceName, ElapsedMilliseconds); 
      } 
     } 

     public static PerformanceEventSource Log = new PerformanceEventSource(); 

     private PerformanceEventSource() 
     { 

     } 
    } 
} 

回答

1

必須首先安裝清單,然後才能啓動EventWriter,並且每次啓動SematicLogger時都可以收集數據。 不幸的是系統拋出錯誤,但現在我很好。

EventSource .net 4.0 GenerateManifest

相關問題