pogorman
pogorman

Reputation: 1711

Nlog console target not working mono?

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" />

Upvotes: 1

Views: 1166

Answers (1)

Julian
Julian

Reputation: 36830

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"/>

Upvotes: 4

Related Questions