SemanticLogging 在 EventSource 的命令处理中抛出异常
SemanticLogging throws Exception in Command Processing for EventSource
在某些机器上(可能只在 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.;
特定场景下发生的一切:
- 我正在启动写入事件的进程
- 然后我 运行 SemanticLogging-svc.exe -c
- 几分钟后发生错误
但是当我改变顺序并首先开始 SemanticLogging-svc.exe
然后我 运行 “event writer
”, 一切正常。
但是当我按照第一个场景中的描述设置所有内容并在出现错误后,我将尝试使用 PerfView
收集数据,奇迹发生了并且 SemanticLogging
开始收集数据。
使用 PerfView 我检查了 Microsoft-SemanticLogging-Etw
来源,但那里什么也没有。
语义日志-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());
}
}
}
事件源:
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()
{
}
}
}
需要先安装manifest,然后你就可以启动你的EventWriter,你可以在启动SematicLogger的任何时候收集数据。
不幸的是系统抛出错误,但现在我对此很满意。
EventSource .net 4.0 GenerateManifest
在某些机器上(可能只在 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.;
特定场景下发生的一切:
- 我正在启动写入事件的进程
- 然后我 运行 SemanticLogging-svc.exe -c
- 几分钟后发生错误
但是当我改变顺序并首先开始 SemanticLogging-svc.exe
然后我 运行 “event writer
”, 一切正常。
但是当我按照第一个场景中的描述设置所有内容并在出现错误后,我将尝试使用 PerfView
收集数据,奇迹发生了并且 SemanticLogging
开始收集数据。
使用 PerfView 我检查了 Microsoft-SemanticLogging-Etw
来源,但那里什么也没有。
语义日志-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());
}
}
}
事件源:
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()
{
}
}
}
需要先安装manifest,然后你就可以启动你的EventWriter,你可以在启动SematicLogger的任何时候收集数据。 不幸的是系统抛出错误,但现在我对此很满意。
EventSource .net 4.0 GenerateManifest