Ashkru
Ashkru

Reputation: 1635

NLog: Where is NLog Config?

I coded this:

private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();

public MyClass()
{
    Console.Write("lol");
    Logger.Debug("Debug test...");
    Logger.Error("Debug test...");
    Logger.Fatal("Debug test...");
    Logger.Info("Debug test...");
    Logger.Trace("Debug test...");
    Logger.Warn("Debug test...");
}

And nothing displays.. so I was told to go and add <targets> to the config file, thing is.. where is the config file? Nothing on google, the documentation, or anything like that helps me...

Upvotes: 3

Views: 9884

Answers (3)

Greg Trevellick
Greg Trevellick

Reputation: 1391

Alternatively you can define the config programmatically in C# as explained in the blog docs here: https://github.com/NLog/NLog/wiki/Configure-from-code

Upvotes: 2

Joe
Joe

Reputation: 369

Sample Nlog.config File for your reference:

<?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"
      throwConfigExceptions="true">

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

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

See also: https://github.com/NLog/NLog/wiki/Tutorial

Upvotes: 2

Ofir Winegarten
Ofir Winegarten

Reputation: 9355

From NLog Wiki:

The following locations will be searched when executing a stand-alone *.exe application:

  • standard application configuration file (usually applicationname.exe.config)
  • applicationname.exe.nlog in application’s directory
  • NLog.config in application’s directory
  • NLog.dll.nlog in a directory where NLog.dll is located (only if NLog isn't installed in the GAC)

So, the easiest would be to add a NLog.config file in the application’s directory

Upvotes: 7

Related Questions