datalust / seq-tickets

Issues, design discussions and feature roadmap for the Seq log server
https://datalust.co/seq
97 stars 5 forks source link

duplicate enrich properties fail to log to seq #131

Closed chandmk closed 10 years ago

chandmk commented 10 years ago

We wrote an enricher which as a run time bug.

// enrich method var properties = new List { new LogEventProperty("LoginName", new ScalarValue(userContext.LoginName)) , new LogEventProperty("LoginName", new ScalarValue(userContext.FirstName) }; var eventProperties = new LogEventProperty(PropertyName, new StructureValue(properties)); logEvent.AddPropertyIfAbsent(eventProperties); }

LoginName is repeated twice by accident. Now this kind of error fails to write to seq. There are no exceptions thrown anywhere.

How to track the failures to write to Seq? Or should serilog throw an error if this causes a failure to write to Seq?

nblumhardt commented 10 years ago

Hi - setting SelfLog.Out = // (some TextWriter) should reveal these; there's a Serilog PR/ticket we're looking at to make this experience a bit better: https://github.com/serilog/serilog/pull/127

A cleaner way to write the enricher might be:

void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
  var property = propertyFactory.CreateProperty(
    PropertyName,
    new { LoginName = userContext.LoginName },
    destructureObjects: true);

  logEvent.AddPropertyIfAbsent(property);
}

Hope this helps, would appreciate any feedback and ideas on that Serilog item, I think this will be a good general scenario to solve in Serilog.

Thanks for the report!

chandmk commented 10 years ago

Thanks for the tips. I will take a look at serilog item. We are writing multiple enrichers.