Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 2.15 KB

README.md

File metadata and controls

50 lines (38 loc) · 2.15 KB

Audit.NET.Serilog

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

Store the audit events using Serilog™.

Install

NuGet Package

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

PM> Install-Package Audit.NET.Serilog

NuGet Status NuGet Count

Usage

Please see the Audit.NET Readme

Configuration

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

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

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

Audit.Core.Configuration.Setup()
    .UseSerilog(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()
    .UseSerilog(config => config
        .Logger(ev => LogManager.GetLogger(ev.EventType))        
        .LogLevel(ev => ev.Environment.Exception != null ? LogLevel.Fatal : LogLevel.Info));

Settings

  • Logger: Indicates the Serilog 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.