Benutzer:MovGP0/Akka.NET/Logging

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Akka.NET Logging

[Bearbeiten | Quelltext bearbeiten]
Logging NuGet Packages Overview
Package Description Targets
Akka built-in logging colored console output (ie. errors in red)
Akka.Logger.Serilog Serilog Files, SQL Server, RavenDB, Windows EventLog, Seq Server, Elasticsearch, etc.
Akka.Logger.NLog NLog Files, SQL Server, Windows EventLog, Email, MSMQ, ASP.NET Trace, etc.
Akka.Logger.slf4net Simple Logging Facade Wrapper for NLog, log4net, and custom logging solutions
public class MyActor : ReceiveActor
{
    private ILoggingAdapter Log { get; } = Context.GetLogger();

    public MyActor()
    {
        Receive<MyMessage>(OnMyMessage);
    }

    private void OnMyMessage(MyMessage message)
    {
        Log.Info("Got message {0}", message.Content);
        try
        {
            // do something
        }
        catch(Exception ex)
        {
            Log.Error(ex, ex.Message);
            throw;
        }
    }
}
App.config/Web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configsections>
    <section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
    <!-- ... -->
  </configsections>
  <akka>
    <hocon>
      <![CDATA[
akka {  
    stdout-loglevel = DEBUG
    loglevel = WARN
    log-config-on-start = on
    loggers = ["Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog", "Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog", "..."]
    actor { # logging akka events
        debug { # debug level and above
              receive = on
              autoreceive = on
              lifecycle = on
              event-stream = on
              unhandled = on
        }
    }
}
      ]]>
    </hocon>
  </akka>
  <!-- NLog configuration -->
  <!-- ... -->
</configuration>
ERROR
  • actor requires human interaction to fix
  • dependent resource (database, web-service) requires human to fix
  • serious problems that halt production
  • information for administrator or developer
WARN
  • expected error/exception which handeled by the actor or actor supervisor
  • condition that may lead to future error
  • does not halt production
  • information for administrator or developer
INFO
  • useful information
  • information for developer, administrator, or business intelligence
DEBUG
  • low-level events (ie. actor lifecycle)
  • fault diagnosis and development

see also: Logging