I am logging error messages and .NET exceptions of my application in a database and display them on a GUI. The GUI displays error messages in the language of the locale of the user running the application. In order to achieve this I log resource names of error messages only, and turn them into meaningful messages using resource files.
I, however, cannot wrap my head around how to achieve the same for .NET standard exception messages. I can only log the message string, but then the language is already 'baked in' so I can only display the exception in that single language.
Is there a way to get the resource name of the .NET exception + all parameters that are inserted into the message string, so that I can log these?
There is no such thing as resource name for an exception, but there is the HResult
property of the Exception
class. The standard .NET framework exceptions have valid and unique HResult
numbers which you can map then to your own resource identifier that you can translate then.
Furthermore there is the Exception.Data
property as well, which may contain additional information about the exception.
Or, you can parse the exception messages manually, using regex or such and then map to your resource id, but this is too much effort I think.
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