如何在Windows IoT中记录事件? [英] How do I log events in Windows IoT?

查看:112
本文介绍了如何在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.

按照与示例中类似的逻辑,我正在执行

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.

推荐答案

  1. 阅读并理解 EventSource用户指南
  2. 将从 EventSource 并按照链接指南中的说明实施您的方法. 此处.
  3. 构建项目,找到项目输出(yourProject.winmd)
  4. 此处
  5. 获取EventRegister.exe实用程序
  6. 运行EventRegister.exe -UsersGuide.阅读并了解用法.
  7. 运行eventRegister.exe -DumpRegDlls yourProject.winmd.这将生成yourProject.MyEwtProvider.etwManifest.dllyourProject.MyEwtProvider.etwManifest.man文件.
  8. 在Windows IoT设备上创建一个新文件夹,例如C:\Events或使用现有文件夹.
  9. 在编辑器中打开yourProject.MyEwtProvider.etwManifest.man并编辑resourceFileNamemessageFileName路径,使父文件夹为C:\Events
  10. yourProject.MyEwtProvider.etwManifest.dllyourProject.MyEwtProvider.etwManifest.man复制到Windows IoT上的C:\Events文件夹中. 注意:最简单的方法是在Windows资源管理器中以\\yourdevice\c$的身份打开Windows共享
  11. 使用Powershell连接到Windows IoT.运行cd C:\Events
  12. 运行wevtutil.exe im .\yourProject.MyEwtProvider.etwManifest.man.这不应产生任何警告或错误.有关wevtutil.exe语法的详细信息,请参考此页面./li>
  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.

现在,如果您按问题导航至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中记录事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆