SemanticLogging在EventSource的命令处理中抛出异常

时间:2017-06-14 06:56:37

标签: etw semantic-logging

在某些机器上(可能仅在Windows 7和2008 R2上,但在Windows 10上),我在使用SemanticLogging时遇到问题。当我运行它时,我接收到了输出:

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. 片刻之后发生错误
  4. 但是,当我更改订单并首先启动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 个答案:

答案 0 :(得分:1)

首先需要安装清单,然后您可以启动EventWriter,并且可以在任何时候启动SematicLogger时收集数据。 不幸的是系统会抛出错误但是现在我很擅长。

EventSource .net 4.0 GenerateManifest