【问题标题】:Is NLog logging supported in UWP windows 10?UWP windows 10 是否支持 NLog 日志记录?
【发布时间】:2018-07-06 17:39:14
【问题描述】:

我需要将日志写入安装 UWP 应用程序的系统的事件查看器。请帮忙

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets>
    <target xsi:type="EventLog" name="eventlog" layout="${message}" machineName="." source="TestNlog" log="MyTestNlog" />    
  </targets>
  <rules>
    <logger name="*" minlevel="Trace" writeTo="eventLog" />
  </rules>  
</nlog>

【问题讨论】:

    标签: c# uwp nlog event-viewer


    【解决方案1】:

    UWP 应用以沙盒方式运行,应用的 InstalledLocation 无法写入,只能读取。您可以尝试使用Windows.Storage.ApplicationData.Current.LocalFolder 写入日志。你可以参考这个问题Log to file in UWP application

    更多关于UWP app的文件访问权限,请看官方文档: https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions#application-data-locations

    【讨论】:

      【解决方案2】:

      通常 UWP 应用程序的访问权限非常有限(甚至对磁盘),因此写入 EventLog 可能不起作用。

      但 NetCore 默认不支持 EventLog,但微软已经让 NetCore2 应用程序可以访问 EventLog:

      https://www.nuget.org/packages/NLog.WindowsEventLog/

      【讨论】:

        猜你喜欢
        • 2012-04-12
        • 2018-06-06
        • 2021-04-29
        • 2017-04-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-29
        相关资源
        最近更新 更多