Search code examples
c#unity-game-engineuwphololensetw

Write HoloLens 2 application logs to Windows Device Portal


I am working on a HoloLens 2 application using Unity which includes some features (mainly UDP connection to other device) that requires the application to be deployed to the HoloLens for most test cases - Holographic Remoting and Unity Play Mode are not working for this purpose.

To still get a comfortable real-time debug log I tried to implement a custom ETW (Event Tracing for Windows) provider in order to make the log entries appear in the Windows Device Portal (web interface for UWP devices). However, I only found instructions from 2016, and can not quite get it to work.

My sources:

https://blogs.windows.com/windowsdeveloper/2016/06/10/using-device-portal-to-view-debug-logs-for-uwp/

https://forums.hololens.com/discussion/2999/remote-logging-with-etw-custom-provider

I added this new class/script to my Unity project:

using System.Diagnostics.Tracing;

namespace Assets.Scripts
{
    [EventSource(Name = "HololensSource", Guid = "69aa67d2-5948-46c5-9b93-0f7fdb0f21cb")]
    internal sealed class HololensSource : EventSource
    {
        public void Message(string message) { Write(message); }
        public static readonly HololensSource Log = new HololensSource();
    }
}

and I am calling it from a couple places in my app where I am sure it is called, like this:

HololensSource.Log.Message("My log message.");

The application builds and runs without error.

In the Device Portal I added the specified Guid under "Custom Providers" and enabled it. When I start the app I do get a few event logs, but they contain no meaningful information, and the events do not pop up when they should, and completely stop after the first few (2-6) events:

Event log in Windows Device Portal

I also tried explicitly specifying the ActivityId appearing in the logs, when writing the log message, but nothing changed.

Has there been any significant change on how to use custom ETW providers and how would I have to realize one these days?

Thanks a lot for any kind of pointers, or viable alternative approaches!


Solution

  • Since HoloLens 2 is based on UWP, it is recommended to use WinRT API to implement ETW. You can refer to this sample(https://github.com/Microsoft/Windows-universal-samples/tree/main/Samples/Logging). For the implementation in Unity, you can also refer to the following code. For more information, please refer to Event Tracing - Win32 apps | Microsoft Learn.

    #if ENABLE_WINMD_SUPPORT
    using Windows.Foundation.Diagnostics;
    #endif
    
        public void SendMessage()
        {
    #if ENABLE_WINMD_SUPPORT
            LoggingChannel lc = new LoggingChannel("SampleProvider", null, new Guid("2df964bb-cd29-4ac0-a462-59b4c484ae3d"));
            lc.LogMessage("send a message");
    #endif
        }
    

    enter image description here