I'm developing a web application in C#, and I have a special exception type, that I need to have a full log from its happenings, and of course I'm going to handle that to show a special message to the user or something.
The question is, is it a good practice to write logging codes inside exception's constructor? I'm asking this because I have not seen something similar to this before.
Thanks in advance
A short and good answer should be: no, you shouldn't go this way becuase you want to develop your code with a good separation of concerns: exception handling isn't logging, thus, logging can't be part of constructing an exception.
If that exception is not handled by your code, you can use a last-chance exception handler like AppDomain.UnhandledException
event and log it there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With