ecs-dotnet
ecs-dotnet copied to clipboard
[BUG] EcsTextFormatter doesn't use the IHostingEnvironment concept in dotnet core
ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog): I'm using the Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog (8.6.1) to output my logs in the ECS standard.
ECS schema version (e.g. 1.4.0): The ecs.version is 8.6.0
ECS .NET assembly version (e.g. 1.4.2): Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog (8.6.1)
Elasticsearch version (if applicable): n/a
.NET framework / OS: .net 6.0
Description of the problem, including expected versus actual behavior: Depending on the stage I run my application in different environements like Testing, Staging or Production. There are different ways doing this:
- setup the environment variable with DOTNET_ENVIRONEMENT={STAGE}
- start the application with the argument parameter --environment {STAGE}
Anyway in microsoft dotnet we have the concept of IHostBuilder who is responsible to setup the IHostingEnvironment. I would expect that in the log output the application name and the application environment will be used from IHostingEnvironment if no other variables like ELASTIC_APM_ENVIRONMENT, OTEL_RESOURCE_ATTRIBUTES or deployment.environment variables are existing.
Starting a console application could be look like on windows:
$ ./JustAApplication.Console.exe --environment Testing --applicationName JustAnother.Application
Actual behaviour of the log output:
{
"service": {
"name": "JustAApplication.Console",
"type": "dotnet",
"version": "1.0.0"
},
...
}
Expected behaviour of the log output:
{
"service": {
"name": "JustAnother.Application",
"environment": "Testing",
"type": "dotnet",
"version": "1.0.0"
},
...
}
Steps to reproduce:
- Start a dotnet application using Host.CreateDefaultBuilder(arguments).Run();
- Log an output using the ECS standard with Elastic.CommonSchema.Serilog.EcsTextFormatter, Elastic.CommonSchema.Serilog
- view the logs and you see that service.environment is not present and the service.name is not like ApplicationName