/Akka.Logger.NLog

Akka.NET logging integration for NLog library

Primary LanguageF#Apache License 2.0Apache-2.0

Akka.Logger.NLog

Build status NuGet Version

This is the NLog integration plugin for Akka.NET.

Configuration

Configuration via code

// Step 1. Create configuration object 
var config = new NLog.Config.LoggingConfiguration();

// Step 2. Create targets and configure properties
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
logconsole.Layout = @"${date:format=HH\:mm\:ss} ${level} ${logger} ${message}";

// Step 3. Define filtering rules
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logconsole);
            
// Step 4. Activate the configuration         
NLog.LogManager.Configuration = config;

Config myConfig = @"akka.loglevel = DEBUG
                    akka.loggers=[""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""]";

var system = ActorSystem.Create("my-test-system", myConfig);

Configuration via NLog.config file

Add NLog.config file to your project

<?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 name="console" xsi:type="Console" layout="[${logger}] [${level:uppercase=true}] [${event-properties:item=logSource}] [${event-properties:item=actorPath}] [${event-properties:item=threadId:format=D4}] : ${message}"/>
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="console"/>
  </rules>
</nlog>

Change your *.csproj file with this content

<ItemGroup>
  <None Include="NLog.config">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>

Change your Akka.NET configuration

Config myConfig = @"akka.loglevel = DEBUG
                    akka.loggers=[""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""]";

var system = ActorSystem.Create("my-test-system", myConfig);

Maintainer

  • Akka.NET Team