注册ETW提供程序有问题。

5
我正在开发一个基于UWP的应用程序,用于Windows 10 IoT。我想配置ETW跟踪,以便可以使用集成的Web界面远程查看日志记录。

ETW List

我相信我已经创建了必要的类型,但是在IoT ETW部分显示的列表中,我无法看到我的提供者:

ETW Options

我的EventListener实现是:

sealed class StorageFileEventListener : EventListener
{
    /// <summary> 
    /// Storage file to be used to write logs 
    /// </summary> 
    private StorageFile _mStorageFile = null;

    /// <summary> 
    /// Name of the current event listener 
    /// </summary> 
    private readonly string _mName;

    public StorageFileEventListener(string name)
    {
        _mName = name;

        Debug.WriteLine("StorageFileEventListener for {0} has name {1}", GetHashCode(), name);

        AssignLocalFile();
    }

    private async void AssignLocalFile()
    {
        _mStorageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(_mName.Replace(" ", "_") + ".log",
                                                                                  CreationCollisionOption.OpenIfExists);
    }

    private async void WriteToFile(IEnumerable<string> lines)
    {
        // TODO: 
    }

    protected override void OnEventWritten(EventWrittenEventArgs eventData)
    {
        // TODO: 
    }

    protected override void OnEventSourceCreated(EventSource eventSource)
    {
        // TODO: 
    }
}

我的 EventSource 实现是:

internal sealed class Logger : EventSource
{
    public static Logger Log = new Logger();

    [Event(1, Level = EventLevel.Verbose)]
    public void Debug(string message, Exception exception)
    {
        var exceptionMessage = GenerateExceptionMessage(exception);
        WriteEvent(1, message + exceptionMessage);
    }

    [Event(2, Level = EventLevel.Informational)]
    public void Info(string message, Exception exception)
    {
        var exceptionMessage = GenerateExceptionMessage(exception);
        WriteEvent(2, message + exceptionMessage);
    }

    [Event(3, Level = EventLevel.Warning)]
    public void Warn(string message, Exception exception)
    {
        var exceptionMessage = GenerateExceptionMessage(exception);
        WriteEvent(3, message + exceptionMessage);
    }

    [Event(4, Level = EventLevel.Error)]
    public void Error(string message, Exception exception)
    {
        var exceptionMessage = GenerateExceptionMessage(exception);
        WriteEvent(4, message + exceptionMessage);
    }

    [Event(5, Level = EventLevel.Critical)]
    public void Critical(string message, Exception exception)
    {
        var exceptionMessage = GenerateExceptionMessage(exception);
        WriteEvent(5, message + exceptionMessage);
    }

    private static string GenerateExceptionMessage(Exception exception)
    {
        return exception != null ? $" Exception message - {exception.Message} :: InnerException - {exception.InnerException} :: StackTrace - {exception.StackTrace}" 
                                    : "";
    }
}

最后,我这样初始化和配置我的EventSource / EventListener类型:

        EventListener genericListener = new StorageFileEventListener("MyIoTListener");
        genericListener.EnableEvents(Logger.Log, EventLevel.Critical);

我是否错过了一个基本步骤?

1个回答

1
这并不是让源代码显示在自定义提供者列表中的解决方案,但可以从Web界面访问事件。只需在自定义提供者文本框中输入EventSource的GUID即可。
在手机上,我有一个带有以下事件源的C# UWP应用程序(从此处复制)。
    [EventSource(Guid = "{GUID of EventSource}", Name = "SourceName")] 
    class MyEventSource : EventSource
    {
        public void MyEvent(string msg, int id) { WriteEvent(1, msg, id); }

        public static MyEventSource Log = new MyEventSource();
    }

我正在使用Windows设备门户API(在此处描述),并在我的桌面应用程序中使用以下过程来读取事件:
  1. 连接到ws://127.0.0.1:10080/api/etw/session/realtime的Web套接字
  2. 发送"provider {EventSource的GUID} enable 5"
  3. ...读取事件,
  4. 发送"provider {EventSource的GUID} disable"
这一切都运行良好,但是当我查询http://127.0.0.1:10080/api/etw/customproviders时,列表仍然为空。
在桌面平台上,我了解到可以使用wevtutil.exe
wevtutil.exe im {App-Manifest}.man

我希望寻找一个类似的解决方案,但不确定它是否适用于Windows Mobile。


由于EventSource从名称生成GUID,因此您需要使用https://github.com/jonwagner/EventSourceProxy/wiki/Getting-the-EventSource-Manifest-or-GUID获取GUID。 - Lars Truijens

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接