1

I have a very simple console app. I've added Nlog with the console target, but I can't get it to work when running in mono (on windows and ubuntu). I've tried the file target and it works. What am I missing?

Code

class Program
{
    private static Logger logger = LogManager.GetCurrentClassLogger();
    static void Main(string[] args)
    {
        Type t = Type.GetType("Mono.Runtime");
        if (t != null)
            Console.WriteLine("You are running with the Mono VM");
        else
            Console.WriteLine("You are running something else");

        Console.WriteLine("Lets go Mono");
        logger.Trace("Sample trace message");
        logger.Debug("Sample debug message");
        logger.Info("Sample informational message");
        logger.Warn("Sample warning message");
        logger.Error("Sample error message");
        logger.Fatal("Sample fatal error message");
    }
}

Config

<?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 async="true">
    <target name="console" xsi:type="Console"/>
  </targets>

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

Nlog package

 <package id="NLog" version="4.3.10" targetFramework="net452" />
pogorman
  • 1,641
  • 2
  • 22
  • 41

1 Answers1

4

You code and config looks valid.

There is an issue with the Console target on Mono with NLog 4.3.10, which will be fixed in 4.3.11. The detection if the Console is available doesn't work correctly as Environment.UserInteractive isn't working on Mono

For now set detectConsoleAvailable="false" for Mono, so:

<target name="console" xsi:type="Console" detectConsoleAvailable="false"/>
Julian
  • 33,915
  • 22
  • 119
  • 174
  • 1
    Works as expected now. About to start my first mono project - glad to have nlog available, thanks – pogorman Oct 13 '16 at 15:41