A Serilog enricher to dynamically add properties to all log events of your application.
The main difference is that
Serilog.Enrichers.GlobalLogContext allows you to add properties at a later time, long after your Serilog logging pipeline has been configured, which can be very useful in scenarios where the properties being added are not immediately available during the bootstrapping of the app. In addition, properties in the
GlobalLogContext can be replaced or removed at any time during the execution of the app.
Log.Logger = new LoggerConfiguration() .Enrich.FromGlobalLogContext() // ... other configuration ... .CreateLogger();
GlobalLogContext.PushProperty("AppVersion", GetThisAppVersion()); GlobalLogContext.PushProperty("OperatingSystem", GetCurrentOS());