2017-06-14 56 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

相关问题