Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Serilog.Sinks.Elasticsearch don't call any error handlers when logs are rejected #357

Closed
1 of 2 tasks
Evolva opened this issue Sep 16, 2020 · 1 comment
Closed
1 of 2 tasks

Comments

@Evolva
Copy link
Contributor

Evolva commented Sep 16, 2020

Does this issue relate to a new feature or an existing bug?

  • Bug
  • New Feature

What version of Serilog.Sinks.Elasticsearch is affected? Please list the related NuGet package.
8.2.0

Please describe the current behavior?
When an LogEvent is rejected from ElasticSearch none of the configure handlers are called

Please describe the expected behavior?
Configured handlers should be called

Analysis
After some digging it seems that:
https://github.com/serilog/serilog-sinks-elasticsearch/blob/1cf2748b7a85fdd95b2c863ed7d5c54a2252a78c/src/Serilog.Sinks.Elasticsearch/Sinks/ElasticSearch/ElasticSearchSink.cs#L224-L233

don't detect my error because settings is already a Dictionary<string, object>
issue_ES_Sink

I rebuild a new version of the sink with

private static bool HasProperty(dynamic settings, string name)
{
    if (settings is IDictionary<string, object>)
        return ((IDictionary<string, object>)settings).ContainsKey(name);
    
    if (settings is System.Dynamic.DynamicObject)
        return ((System.Dynamic.DynamicObject)settings).GetDynamicMemberNames().Contains(name);

    return settings.GetType().GetProperty(name) != null;
}

and it worked.

@mivano
Copy link
Contributor

mivano commented Sep 16, 2020

Thanks for raising this and providing a PR! It is merged to master, trying to collect some more needed changes and bring a package out.

@mivano mivano closed this as completed Sep 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants