如何在Windows IoT中记录事件? [英] How do I log events in 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.
推荐答案
- 阅读并理解 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 generateyourProject.MyEwtProvider.etwManifest.dll
andyourProject.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 editresourceFileName
andmessageFileName
paths so that the parent folder isC:\Events
- Copy
yourProject.MyEwtProvider.etwManifest.dll
andyourProject.MyEwtProvider.etwManifest.man
over to your Windows IoT to theC:\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 onwevtutil.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屋!