如何在Windows IoT中记录事件?

编程入门 行业动态 更新时间:2024-10-27 04:25:18
本文介绍了如何在Windows IoT中记录事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

用于Windows IoT的WebUI(在Raspberry PI上可以看到)具有以下事件跟踪"屏幕:

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

我如何从uwp程序写入事件日志,然后再检查那里写了什么?

How do I write into an event log from a uwp program and then later examine what's written there?

此答案(与Windows IoT无关)建议您需要使用标准的System.Diagnostics.Tracing类为了它.该答案所指的示例是为了演示记录到文件.登录到诸如ETW之类的内置工具后,我的想法更多了.

This answer (which is not about Windows IoT) suggests that you need to use standard System.Diagnostics.Tracing classes for it. The sample that this answer is referring to is to demonstrate logging to a file. I'm more after logging to a built-in facility, such as ETW.

按照与示例中类似的逻辑,我正在执行 EventSource.Write ,它不会引发错误,但是看不到书面消息.

Following similar logic as in the sample I'm executing EventSource.Write and it does not throw a error, but written message is nowhere to be seen.

用于Windows IoT的Windows Powershell也不支持Get-EventLog命令.

Windows Powershell for Window IoT does not support Get-EventLog command either.

Windows IoT的开发相对较新,因此互联网上没有太多信息.当前最好的来源是 Mot Iot Samples ,但是尽管有大量的样本,但似乎都没有做任何事件记录.

Windows IoT development is relatively new, so there is not much information in the internet. The best source currently is Ms Iot Samples but despite huge number of samples none of them seem to be doing any event logging.

推荐答案

  • 阅读并理解 EventSource用户指南
  • 将从 EventSource 并按照链接指南中的说明实施您的方法. 此处.
  • 构建项目,找到项目输出(yourProject.winmd)
  • 从此处
  • 获取EventRegister.exe实用程序
  • 运行EventRegister.exe -UsersGuide.阅读并了解用法.
  • 运行eventRegister.exe -DumpRegDlls yourProject.winmd.这将生成yourProject.MyEwtProvider.etwManifest.dll和yourProject.MyEwtProvider.etwManifest.man文件.
  • 在Windows IoT设备上创建一个新文件夹,例如C:\Events或使用现有文件夹.
  • 在编辑器中打开yourProject.MyEwtProvider.etwManifest.man并编辑resourceFileName和messageFileName路径,使父文件夹为C:\Events
  • 将yourProject.MyEwtProvider.etwManifest.dll和yourProject.MyEwtProvider.etwManifest.man复制到Windows IoT上的C:\Events文件夹中. 注意:最简单的方法是在Windows资源管理器中以\\yourdevice\c$的身份打开Windows共享
  • 使用Powershell连接到Windows IoT.运行cd C:\Events
  • 运行wevtutil.exe im .\yourProject.MyEwtProvider.etwManifest.man.这不应产生任何警告或错误.有关wevtutil.exe语法的详细信息,请参考此页面./li>
  • Read and understand EventSource User’s Guide
  • 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.
  • Build your project, locate project output (yourProject.winmd)
  • Get EventRegister.exe utility from here
  • Run EventRegister.exe -UsersGuide. Read and understand usage.
  • Run eventRegister.exe -DumpRegDlls yourProject.winmd. This will generate yourProject.MyEwtProvider.etwManifest.dll and yourProject.MyEwtProvider.etwManifest.man files.
  • Create a new folder on your Windows IoT device, for example, C:\Events or use an existing one.
  • Open yourProject.MyEwtProvider.etwManifest.man in an editor and edit resourceFileName and messageFileName paths so that the parent folder is C:\Events
  • 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
  • Connect to your Windows IoT with Powershell. Run cd C:\Events
  • 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.
  • 现在,如果您按问题导航至ETW WebUI页面,则"MyEwtProvider"将出现在下拉列表中.您可以通过调用UwpEventSource.Log.Info/Warn/Debug/Critical/Error("Hello from my porgram");

    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");

    如果您不想在不使用WebUI时收集事件,则可以完成.如果您希望能够保留它们并在以后进行分析,请在powershell会话中运行以下命令:

    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

    更多推荐

    如何在Windows IoT中记录事件?

    本文发布于:2023-11-15 17:34:59,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1596545.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:事件   如何在   Windows   IoT

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!