NLog storage provider for Audit.NET library (An extensible framework to audit executing operations in .NET).
Store the audit events using NLog™.
NuGet Package
To install the package, run the following command on the Package Manager Console:
PM> Install-Package Audit.NET.NLog
Please see the Audit.NET Readme
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));
Logger
: Indicates the NLog ILogger logger instance to use. Default is obtained by using the audit event typeLogManager.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.