Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 2.1 KB

README.md

File metadata and controls

50 lines (38 loc) · 2.1 KB

Audit.NET.NLog

NLog storage provider for Audit.NET library (An extensible framework to audit executing operations in .NET).

Store the audit events using NLog™.

Install

NuGet Package

To install the package, run the following command on the Package Manager Console:

PM> Install-Package Audit.NET.NLog

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

To set the NLog data provider globally, call the UseNLog() method on the fluent configuration API, for example:

Audit.Core.Configuration.Setup()
    .UseNLog();

You can also configure the provider settings by using the fluent API, for example:

Audit.Core.Configuration.Setup()
    .UseNLog(config => config
        .Logger(LogManager.GetLogger(typeof(MyClass)))        
        .LogLevel(LogLevel.Debug)
        .Message(auditEvent => auditEvent.ToJson()));

The Logger and LogLevel settings can be configured as a function of the audit event, for example:

Audit.Core.Configuration.Setup()
    .UseNLog(config => config
        .Logger(ev => LogManager.GetLogger(ev.EventType))        
        .LogLevel(ev => ev.Environment.Exception != null ? LogLevel.Fatal : LogLevel.Info));

Settings

  • Logger: Indicates the NLog ILogger logger instance to use. Default is obtained by using the audit event type LogManager.GetLogger(auditEvent.GetType()).
  • LogLevel: Indicates the log level to use (debug, info, warn, error or fatal). Default is Info unless there is an exception, in which case it logs as Error.
  • Message: Indicates the textual message to log. Default is the AuditEvent JSON including the EventId as a custom field.