Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datadog is not updating dynamic values after configuration is read from appsettings. #300

Open
zinov opened this issue Feb 9, 2022 · 0 comments

Comments

@zinov
Copy link

zinov commented Feb 9, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant