How do I log events in Windows IoT?

后端 未结 1 1707
滥情空心
滥情空心 2020-12-11 09:21

WebUI for Windows IoT (as seen on Raspberry PI) features the following Event Tracing screen:

How do I write into an event log from a uwp program and then la

相关标签:
1条回答
  • 2020-12-11 10:03
    1. Read and understand EventSource User’s Guide
    2. Add a class to your project that derives from EventSource and implement your methods as described in the linked guide. A sample implementation is available here.
    3. Build your project, locate project output (yourProject.winmd)
    4. Get EventRegister.exe utility from here
    5. Run EventRegister.exe -UsersGuide. Read and understand usage.
    6. Run eventRegister.exe -DumpRegDlls yourProject.winmd. This will generate yourProject.MyEwtProvider.etwManifest.dll and yourProject.MyEwtProvider.etwManifest.man files.
    7. Create a new folder on your Windows IoT device, for example, C:\Events or use an existing one.
    8. Open yourProject.MyEwtProvider.etwManifest.man in an editor and edit resourceFileName and messageFileName paths so that the parent folder is C:\Events
    9. Copy yourProject.MyEwtProvider.etwManifest.dll and yourProject.MyEwtProvider.etwManifest.man over to your Windows IoT to the C:\Events folder. Note: the simplest way to do this is to open windows share as \\yourdevice\c$ in Windows Explorer
    10. Connect to your Windows IoT with Powershell. Run cd C:\Events
    11. Run wevtutil.exe im .\yourProject.MyEwtProvider.etwManifest.man. This should not produce any warnings or errors. Please refer to this page for the details on wevtutil.exe syntax.

    Now if you navigate to your ETW WebUI page as in your question "MyEwtProvider" will appear in the drop down. You log events in your program by calling one of the UwpEventSource.Log.Info/Warn/Debug/Critical/Error("Hello from my porgram");

    If you do not want to collect the events when you are not working with the WebUI you are done. If you want to be able to persist these and analyse them later, run the following command in your powershell session:

    echo y | wevtutil.exe sl MyEwtProvider/Debug /e:true
    

    See what it does here. Now you will be able to retrieve historical data (once you've accumulated them) by running:

    wevtutil.exe qe MyEwtProvider/Debug
    
    0 讨论(0)
提交回复
热议问题