GitHub - serilog/serilog-enrichers-environment: Enrich Serilog log events with properties from System.Environment. (original) (raw)
Serilog.Enrichers.Environment
Enriches Serilog events with information from the execution environment.
To use the enricher, first install the NuGet package:
dotnet add 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()
- addsMachineName
based on either%COMPUTERNAME%
(Windows) or$HOSTNAME
(macOS, Linux)WithEnvironmentUserName()
- addsEnvironmentUserName
based onUSERNAME
andUSERDOMAIN
(if available)WithEnvironmentName()
- addsEnvironmentName
based onASPNETCORE_ENVIRONMENT
orDOTNET_ENVIRONMENT
(when both are available then 'ASPNETCORE_ENVIRONMENT' takes precedence, when none are available then the fallback value will be 'Production')WithEnvironmentVariable(string environmentVariableName, string propertyName = null)
- adds anenvironmentVariableName
property to the log event with the value for the specified environment variable. OptionalpropertyName
will overrideenvironmentVariableName
as the name of the attached property.
Copyright © 2016 Serilog Contributors - Provided under the Apache License, Version 2.0.