Giter VIP home page Giter VIP logo

Comments (13)

krajek avatar krajek commented on May 29, 2024 1

Took me a while to understand what is happening and I found out that this particular exception somehow declares property Content twice. Serilog.Exceptions fails silently in this case so you do not get any enrichment.

image

I will fix it tomorrow and let you know.

from serilog.exceptions.

krajek avatar krajek commented on May 29, 2024

I am using Serilog.Exceptions with ApplicationInsights sink and it works fine.
You need to provide an example https://stackoverflow.com/help/minimal-reproducible-example, for us to check.

Moreover, Serilog.Exceptions is basically unrelated to any particular sink, its code is executed before sink code obviously.

from serilog.exceptions.

domagojmedo avatar domagojmedo commented on May 29, 2024

Yea, my bad, it seems that issue is with Refit.ValidationApiException. It's not getting deconstructed. I'll try to create an example

from serilog.exceptions.

domagojmedo avatar domagojmedo commented on May 29, 2024

I'm having trouble finding a public API that will return that exception.

In this repo everything works when ApiException is caught, but if ValidationApiException is caught then nothing gets deconstructed, not even properties from the base ApiException class.

I'll try to find a public API that throws ValidationApiException but at the moment this is the best I could come up with.

In the meantime I changed my code to serialize Content manually and log it.

catch (ValidationApiException apiException)
{
    var validationError = JsonSerializer.Serialize(apiException.Content);
    _logger.LogError(apiException, "Validation error occured while calling external API {validationError}", validationError);
}

https://github.com/domagojmedo/LoggingExample

from serilog.exceptions.

krajek avatar krajek commented on May 29, 2024

You don't need public API, just create exception manually then log it and verify result in the log output.

from serilog.exceptions.

domagojmedo avatar domagojmedo commented on May 29, 2024

I tried but had issues because it required APiException in constructor. Switched to using reflection now.

Repo is updated, you can see that Content is set to some ProblemDetails object, but nothing is output in console.
If you uncomment ThrowApiException and comment that method you will see that it works as intended

from serilog.exceptions.

krajek avatar krajek commented on May 29, 2024

Ok, it just overrides the definition of Content with new keyword.

image

from serilog.exceptions.

RehanSaeed avatar RehanSaeed commented on May 29, 2024

If someone has used the new keyword on a property, they are deliberately hiding the one the base class. I'm not really sure we should we be retrieving both. In this case, the derived class looks like it gives us a better representation of the content (ProblemDetails) than the base class (String). Thoughts @krajek?

from serilog.exceptions.

krajek avatar krajek commented on May 29, 2024

@RehanSaeed yes, agreed 100%, next PR will tackle that problem.

Just to reiterate: this PR is just a safety mechanism, the last line of defense, but not the only one.
I assume that robustness(meaning in that case "providing value to the library user" even in the unexpected scenario) is so important for our library that such a mechanism is justifiable.
I will start the next PR just after this is merged.

from serilog.exceptions.

domagojmedo avatar domagojmedo commented on May 29, 2024

@RehanSaeed when can we expect new version with this fix?

from serilog.exceptions.

RehanSaeed avatar RehanSaeed commented on May 29, 2024

@krajek Do you want to put in another PR with further improvements? E.g. using ConcurrentDictionary?

from serilog.exceptions.

krajek avatar krajek commented on May 29, 2024

from serilog.exceptions.

RehanSaeed avatar RehanSaeed commented on May 29, 2024

Released in https://github.com/RehanSaeed/Serilog.Exceptions/releases/tag/7.0.0

from serilog.exceptions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.