elastic / elastic/ecs-dotnet

Support serializing exceptions like Serilog.Sinks.Elasticsearch

Open
#158 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
HTML
Stars
137
Forks
70
PR merge metrics
No merged PRs in 30d

Description

Potential dupe of #139 , but am still facing the same issue with Serilog on 1.5.3

**ECS integration/library project(s) (e.g. Elastic.CommonSchema.Serilog)**: Elastic.CommonSchema.Serilog

**ECS schema version (e.g. 1.4.0)**: 1.5.3

**ECS .NET assembly version (e.g. 1.4.2)**: 1.5.3

**Elasticsearch version (if applicable)**: 7.13.1

**.NET framework / OS**: .NET 5.0 / windows 10

**Description of the problem, including expected versus actual behavior**:
When using ECS with Serilog, exception properties are not sent to ES. I expect to see various `exceptions.*` properties in my log messages.

**Steps to reproduce**:
I'm configuring Serilog with the ES sink like so:
```c#
var elasticSinkOptions = new ElasticsearchSinkOptions(new Uri(elasticSettings.Uri))
{
AutoRegisterTemplate = true,
IndexFormat = $"logs-{indexName}",
BatchAction = ElasticOpType.Create,
CustomFormatter = new EcsTextFormatter()
};
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext()
.Enrich.WithProperty("Application", "MyService")
.WriteTo.Elasticsearch(elasticSinkOptions)
.WriteTo.Console(outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}");
```

When doing e.g.:
```c#
try
{
throw new Exception("Some exception");
}
catch (Exception e)
{
Log.LogError(e, "Error occurred");
}
```
The log is sent to ES, but does not include information about the exception, the custom property (`.Enrich.WithProperty("Application", "MyService")`), does get sent to ES.
When removing `CustomFormatter = new EcsTextFormatter()` from the ES sink configuration, the exception does get sent to ES (in the `exceptions.*` properties), but my custom property not anymore.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.