Vilayat Ali
Vilayat Ali

Reputation: 1

Is NLog logging supported in UWP windows 10?

I need to write logs to Event Viewer of the System where UWP application is installed. Please help

<?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>

Upvotes: 0

Views: 2706

Answers (2)

Rolf Kristensen
Rolf Kristensen

Reputation: 19857

Usually UWP applications have very restricted access (even to disk), so writing to EventLog might not work.

But the EventLog is not supported by default on NetCore, but Microsoft have made it possible for NetCore2 applications to access the EventLog:

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

Upvotes: 0

Breeze Liu - MSFT
Breeze Liu - MSFT

Reputation: 3808

UWP app runs sandboxed and the app's InstalledLocation can not be written into, it only can be reader. You can try to use Windows.Storage.ApplicationData.Current.LocalFolder to write the logs. You can refer this issue Log to file in UWP application.

More details about UWP app File access permissions, please see the official document: https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions#application-data-locations

Upvotes: 2

Related Questions