serilog-settings-configuration
serilog-settings-configuration copied to clipboard
Datadog is not updating dynamic values after configuration is read from appsettings.
I need to override dynamic values like host or service name coming from datadog appsettings.json Here is my configuration:
"Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.Datadog.Logs" ], "MinimumLevel": "Debug", "WriteTo": [ { "Name": "Console" }, { "Name": "DatadogLogs", "Args": { "apiKey": "mykeyvaluehere", "source": "mysource", "host": "myhost", "tags": [ "environment:dev"" ] } } ], "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], "Properties": { "Application": "Sample" } }
C# code to read data with Serilog
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.CreateLogger();
This works fine with the configuration that is coming from the appsettings.json. But I would like to override the source value for example. In my case, my application is running on service fabric, so it means that my code is going to be running on different nodes at a certain point in time and I would like to capture from which one in particular are these logs coming.
What I thought was going to work:
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(Configuration)
.WriteTo
.DatadogLogs("mykeyvaluehere", source: Environment.MachineName)
.CreateLogger();
or
Log.Logger = new LoggerConfiguration()
.WriteTo
.DatadogLogs("mykeyvaluehere", source: Environment.MachineName)
.ReadFrom.Configuration(Configuration)
.CreateLogger();
I also try LoggerContext.PushProperty("dd.source", Environment.MachineName) and nothing