简体   繁体   English

UWP C#如何写入事件日志

[英]UWP C# How to Write to Event Log

I am trying to add an EventLog to my UWP app, but I was not able to reference it in System.Diagnostic. 我试图将EventLog添加到我的UWP应用中,但无法在System.Diagnostic中引用它。 After doing some research, I'm starting to think that it is not apart of UWP's API. 经过研究后,我开始认为它与UWP的API无关。 I have found alternatives to writing an EventLog using both FileLoggingSession and LoggingSesssion, but was wondering if there is a way to write to a windows EventLog? 我找到了同时使用FileLoggingSession和LoggingSesssion编写EventLog的替代方法,但是想知道是否有写Windows EventLog的方法吗? If not, is there an Open Source or NuGet package that will do this for me? 如果没有,是否有一个开源或NuGet软件包可以为我做到这一点?

The sandboxed nature of UWP apps means you don't have direct access to the event log. UWP应用的沙盒性质意味着您无权直接访问事件日志。 There are a number of ways around it, but they are not valid in a store-deployed scenario. 有多种解决方法,但是在商店部署的方案中无效。

You can write the Action<string> in a static class and write 您可以在静态类中编写Action<string>并编写

public Action<string> reminder;

Reminder: add the code that writes the file in the Local Folder, and you can see the file that you write. 提醒:在本地文件夹中添加用于写入文件的代码,您可以看到所写入的文件。

And I write the error in catch(Expetion e) and write reminder=e.Message; 然后在catch(Expetion e)中写入错误,并写入hinter reminder=e.Message;

But it cannot see it running. 但是它看不到它正在运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM