我需要编写日志消息并在PerfView中捕获它。我想避免使用EventLog或EventSource,因为它们具有很强的侵入性:它们需要注册一个新的源或ETW提供者,这将在系统中留下剩余的部分。
理想情况下,我只想调用Debug.WriteLine (它使用OutputDebugString,但似乎PerfView无法收集它)。或者是否有看到调试消息的ETW提供程序?
如果您有答案,请说明解决方案的两个部分:
发布于 2019-01-09 16:14:44
您想要的是使用EventSource。在这里,您不需要处理GUID和系统注册。
public sealed class MinimalEventSource : EventSource
{
public class Tasks
{
public const EventTask Information = (EventTask)1;
}
public static MinimalEventSource Log = new MinimalEventSource();
[Event(1, Message = "{0}", Opcode = EventOpcode.Info, Task = Tasks.Information)]
public void Information(string message)
{
if (IsEnabled())
{
WriteEvent(1, message);
}
}
}用MinimalEventSource.Log.Information("my debug info");获取数据,用PerfView /OnlyProviders=*MinimalEventSource实现对数据的截取。最重要的是*。事件源通过ManifestEvent记录Manifest,该定义被添加到ETL中,因此不需要清单注册。
https://stackoverflow.com/questions/54070364
复制相似问题