How to match thrown exception with event id for logging?

In our code base, an error condition may throw an exception. Elsewhere in the code, the exception handler throws an exception and logs the error in the Windows event log.

When an error is detected and an exception is thrown, we have the largest error information, and I would like to identify the error with a unique event identifier that will be logged in the Windows event log.

What is the best way to include this event id in the exception that is thrown?

I was thinking about using Exception.HResult , but it seems to be intended for use in COM / win32 interop. Do people use HResult for this purpose? It seems that you can match the severity with the log level, the object code with the Event source, and the Hresult code with the event ID. Is this a general approach?

I thought about using the Exception.Data dictionary and adding the "EventID" value to the exception raised, so my handler can use this value to register the EventID.

Anyone have any good tips or suggestions?

+4
source share
1 answer

, , , . , , , , .

, , , , InnerException, , . , , , , HResult Exception.Data.

+3

Source: https://habr.com/ru/post/1536492/


All Articles