NLog doesn't log in Uwp project

545 views Asked by At

I try to use NLog in my Uwp application. I've added NLog nuget package to the project, created NLog.config file in the project directory, maken it Copy always

<?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"
      internalLogLevel="Trace"
      internalLogFile="C:\NlogLogs.txt"
      internalLogToConsole="true"
      internalLogToConsoleError="true"
      internalLogToTrace="true">

  <targets>
    <target concurrentWrites="false" name="logfile" xsi:type="File" fileName="file.txt" />
    <target name="logconsole" xsi:type="Console" />
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="logconsole" />
    <logger name="*" minlevel="Trace" writeTo="logfile" />
  </rules>
</nlog>

Added logger into MainViewModel class (see below), and tried to log, but it hasn't worked. There aren't any file.txt in my bin/Debug folder or anywhere else, but no exceptions are occurred.

Why? How can I setup logging into UWP project?

 public class MainViewModel : ViewModelBase
    {

        private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();

        public MainViewModel()
        {

            logger.Trace("Started MainViewModel");
            logger.Info("Started MainViewModel");
        }
0

There are 0 answers