Skip to content

Commit

Permalink
NLog GoogleStackdriverTarget improve handling of dangerous object pro…
Browse files Browse the repository at this point in the history
…perties that throws exceptions during Json.Net serialization. (#3668)
  • Loading branch information
snakefoot authored and chrisdunelm committed Oct 28, 2019
1 parent 3f9b1d0 commit e708f35
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ protected override void InitializeTarget()
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
};
jsonSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
jsonSettings.Error = (sender, args) =>
{
// Serialization of properties that throws exceptions should not break everything
InternalLogger.Warn(args.ErrorContext.Error, "GoogleStackdriver(Name={0}): Error serializing exception property: {1}", Name, args.ErrorContext.Member);
args.ErrorContext.Handled = true;
};
var jsonSerializer = Newtonsoft.Json.JsonSerializer.CreateDefault(jsonSettings);
return o => {
try
Expand Down

0 comments on commit e708f35

Please sign in to comment.