Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble registering an ETW Provider [duplicate]

I am working on a UWP based application for Windows 10 IoT and I am wanting to configure ETW Tracing so I can view logging remotely using the integrated web interface:

ETW List

I believe I have created the necessary types, however I cannot see my provider in any of the lists shown within the IoT ETW section:

ETW Options

My EventListener implementation is:

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: 
    }
}

My EventSource implementation is:

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}" 
                                    : "";
    }
}

Finally, I initialise and configure my EventSource/EventListener types like so:

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

Am I missing a fundamental step?

like image 813
Jamie Keeling Avatar asked Nov 09 '22 04:11

Jamie Keeling


1 Answers

This is not a solution for making the source appear on the custom provider list, but does provide access to the events from the web interface. Just type in the GUID of the EventSource into the custom providers text box.

On the phone, I have a C# UWP app with the following event source, (copied from here)

    [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();
    }

I'm using the Windows Device Portal API (described here), and use the following process in my desktop app to read events:

  1. Connect a web socket to ws://127.0.0.1:10080/api/etw/session/realtime
  2. Send "provider {GUID of EventSource} enable 5"
  3. ...Read events,
  4. Send "provider {GUID of EventSource} disable"

This all works well and good, however, when I query http://127.0.0.1:10080/api/etw/customproviders, the list is still empty.

On the desktop platform I understand one uses wevtutil.exe:

wevtutil.exe im {App-Manifest}.man

for a similar purpose, but don't know if it applies to windows mobile.

like image 113
Andrew Malcolm Avatar answered Nov 14 '22 22:11

Andrew Malcolm