Possible Duplicate:
How to get the Stack trace when logging exceptions with NLog?
What is the best practice to throw exception to get a clear picture from the log?
For logging, I am using NLog.
Below is the simple code:
catch (Exception ex)
{
logger.Fatal(ex.Message);
throw new Exception(ex.Message);
}
It does not give me a good logging message. I need info like, the function, the error code line.
For loggin purpose you are going analyse much more than just message field of exception object.
This link will give you info of what you can get from generic Exception object
Also, there is a difference between
throw exandthrow. And moreover when you throw newly created exception.throw new Exception(ex.Message)) you are throwing generic exception that doest say anything about nature of exception and has new stacktrace, build from this line of code.throw ex– rethrows original exception, but cut stacktrace to current catch clausethrow– rethrows original exception with original stacktrace allowing you to log etc exception and let it go furtherSo depending on what you are going to achieve one of this three cases would meet your needs.