Oh boy, you should never ever do that for log message ever. The reason is pretty simple, you will construct strings every time no matter if the message is logged or not. Use the proper logger template mechanics instead (learn.microsoft.com/en-us/dotn…, github.com/serilog/serilog/wik…).
Keep in mind if you use a structured logger like Serilog then if you interpolate the string then it won't pick out the structured properties. It took us a while to figure that out
@bigolewannabe I think someone else already answered, but since serilog supports structured logging, you can have a much better output by naming the values in the message template and passing the values in instead of using string interpolation There are analyzers to guide you toward that pattern too github.com/serilog/serilog/wik…
@bigolewannabe No! Even worse 😅 Each logging method have an overload, taking the exception as the first parameter ex: ``` Logger.Information(exception, "Something bad happened here"); ```
@esg @bigolewannabe If you throw the exception as well, then yes, it is fine because there is no other possible execution branch continuing. That said, you should always throw an exception right after construction anyway, so there's no issue there. However throwing an exception just to log it is a bit of an anti-pattern as well, you should log and then throw when possible (allows to generate logger properties which can later be filtered/used with structured logging).
Damselfly - Photo Management 📷
in reply to André Polykanine • • •André Polykanine
in reply to Damselfly - Photo Management 📷 • • •MaxiTB
in reply to André Polykanine • • •André Polykanine
in reply to MaxiTB • • •Matt Boehm
in reply to André Polykanine • • •André Polykanine
in reply to Matt Boehm • • •ESG
in reply to André Polykanine • • •There are analyzers to guide you toward that pattern too
github.com/serilog/serilog/wik…
André Polykanine
in reply to ESG • • •André Polykanine
in reply to ESG • • •ESG
in reply to André Polykanine • • •Each logging method have an overload, taking the exception as the first parameter
ex:
```
Logger.Information(exception, "Something bad happened here");
```
André Polykanine
in reply to ESG • • •MaxiTB
in reply to André Polykanine • • •André Polykanine
in reply to MaxiTB • • •Purgator
in reply to André Polykanine • • •