我想使用ETW进行事件日志记录,并且相信我已经正确设置了所有内容。但是,当应用程序退出时,我在文件中看不到任何事件。我创建并关联了一个FileLoggingSession和LoggingChannel。当我使用LoggingChannel时,我没有得到任何错误。一切似乎都很正常,但日志文件似乎没有我发布的任何消息。
public EtwLogger()
{
_channel = new LoggingChannel(LibSettings._etwLogChannel, null);
_channel.LoggingEnabled += _channel_LoggingEnabled;
_session = new FileLoggingSession(LibSettings._etwLogSession);
_session.LogFileGenerated += _session_LogFileGenerated;
_session.AddLoggingChannel(_channel);
}
public Task Log(LogEntry logEntry)
{
if (!isDisposed && _channel.IsEnabled(SeverityToLoggingLevel(logEntry.Severity)))
{
string message = $"{logEntry.TimeStamp.ToLocalTime().ToString("s")} {SeverityToString(logEntry.Severity)} : ";
if (logEntry.Source?.Length > 0)
message += $"{logEntry.Source} {logEntry.Message}";
else
message += $"{logEntry.Message}";
_channel.LogMessage(message, SeverityToLoggingLevel(logEntry.Severity));
Debug.WriteLine($"ETW: {message}");
}
return Task.FromResult(0);
}发布于 2016-11-22 04:34:10
已解决。当程序终止(或挂起)时,我需要发出.CloseAndSaveToFileAsync()。
https://stackoverflow.com/questions/40725579
复制相似问题