Giter VIP home page Giter VIP logo

Comments (2)

krajek avatar krajek commented on May 31, 2024

Hi @bxbxbx.

There are two major problems with your approach, let me explain each one separately.

The first issue is that exception message is not a template for Serilog. Whether you are using Serilog.Exceptions or not is not relevant.

The second issue is that you do not have to and, in fact, you should never pass ex.Message to as a messageTemplate argument of Serilog's log method. The proper way to use Serilog in your case would be:

var ex = new InvalidOperationException($"SubJob Status<>Startable");
ex.Data.Add("SubJobId", subJobId);
_logger.Fatal(ex, "There was a problem with SubJob with id {SubJobId}, subJobId);

Notice that Fatal method is accepting a proper messageTemplate and a parameter to fill the placeholder. On the other hand, the exception message is not a template, so there is no placeholder.

Is there anything else I could explain?

from serilog.exceptions.

bxbxbx avatar bxbxbx commented on May 31, 2024

Hello @krajek

thx for your elaborate answer.
This is a legacy project, so no IoC yet, but I'm working on that.
I was thinking that this was a way to avoid passing around the logger all the time, but I guess I will have to.

bye!

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.