Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log and display .NET exceptions in multiple languages

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?

like image 292
Daniel Avatar asked Jan 29 '13 22:01

Daniel


1 Answers

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.

like image 64
dbalogh Avatar answered Sep 17 '22 12:09

dbalogh