Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions with large properties #445

Closed
kingwill27 opened this issue Dec 23, 2021 · 3 comments
Closed

Exceptions with large properties #445

kingwill27 opened this issue Dec 23, 2021 · 3 comments
Labels
enhancement Issues describing an enhancement or pull requests adding an enhancement.

Comments

@kingwill27
Copy link

I encountered an issue using Serilog.Exceptions for certain exception types which contain very large properties that exceed the max log size in New Relic (where I ship logs) causing the logs to not be parsed correctly.

In the first case, I am logging a custom Exception with an InnerException of OptimisticConcurrencyException, so the JSON-formatted log looks like this:

{
  ...
  "Message.Properties.ExceptionDetail": {
    ...
    "InnerException": {
      ...
      "StateEntries": [...],
      "Type": "System.Data.Entity.Core.OptimisticConcurrencyException"
    },
    "Type": "MyCustomExceptionType"
  }
}

In the second case, the AutoMapper exception itself is being logged:

{
  ...
  "Message.Properties.ExceptionDetail": {
    ...
    "TypeMap": {...},
    "Type": "AutoMapper.AutoMapperMappingException"
  }
}

I'm happy to make contributions to handle both these exceptions without logging these large properties, but wanted to confirm the best approach before starting.

  1. My initial thought was to write custom destructurers (one for each exception) that explicitly ignore the large properties. Is this the best way to handle it?
  2. Does the nested nature of the first case present any additional concerns, or can it be handled in the same way as the second case?

Also, happy to break this into 2 separate issues if that is preferable.

@RehanSaeed RehanSaeed added the enhancement Issues describing an enhancement or pull requests adding an enhancement. label Feb 19, 2022
@RehanSaeed
Copy link
Owner

Thanks for reporting.

Regarding the first type System.Data.Entity.Core.OptimisticConcurrencyException, am I right in thinking thats the older EF6? If its EF Core, we have an EF package that we should add a custom destructurer to.

We could also add a new package and handle AutoMapper as we have done for Refit. Although, having to add custom destructurers for third party libraries has always left a bad taste in my mouth.

Also FYI, I believe you can use Serilog.Expressions to filter out long properties yourself.

https://github.com/serilog/serilog-expressions

@RehanSaeed
Copy link
Owner

Feel free to reopen if you have more questions or info.

@RehanSaeed
Copy link
Owner

Duplicate of #397 (comment) where I've added a suggested solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues describing an enhancement or pull requests adding an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants