serilog / serilog-enrichers-environment

Enrich Serilog log events with properties from System.Environment.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serilog.Enrichers.Environment

Enriches Serilog events with information from the process environment.

Build status NuGet Version

To use the enricher, first install the NuGet package:

Install-Package Serilog.Enrichers.Environment

Then, apply the enricher to you LoggerConfiguration:

Log.Logger = new LoggerConfiguration()
    .Enrich.WithMachineName()
    // ...other configuration...
    .CreateLogger();

The WithMachineName() enricher will add a MachineName property to produced events.

Included enrichers

The package includes:

  • WithMachineName() - adds MachineName based on either %COMPUTERNAME% (Windows) or $HOSTNAME (macOS, Linux)
  • WithEnvironmentUserName() - adds EnvironmentUserName based on USERNAME and USERDOMAIN (if available)
  • WithEnvironmentName() - adds EnvironmentName based on ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT (when both are available then 'ASPNETCORE_ENVIRONMENT' takes precedence, when none are available then the fallback value will be 'Production')
  • WithEnvironmentVariable(string envVarName, string propertyName = null) - adds an <envVarName> property to the log event with the value for the specified enviroment variable. Optional <propertyName> will override <envVarName> as propertyName.

Copyright © 2016 Serilog Contributors - Provided under the Apache License, Version 2.0.

About

Enrich Serilog log events with properties from System.Environment.

License:Apache License 2.0


Languages

Language:C# 94.7%Language:PowerShell 4.6%Language:Shell 0.7%