Reputation: 484
I don't know if this idea is possible to implement. If not, i would appreciate some alternative.
I need to create an custom exception class that can catch any time of error, as do the System.Exception class. But on catching an exception, it would be able to log the error.
This code is my implementation, but it does not catch any type of exceptions.
public class CustomException : Exception
{
public CustomException()
{
//Log error
}
public CustomException(string message)
: base(message)
{
//Log error
}
public CustomException(string message, Exception inner)
: base(message, inner)
{
//Log error
}
}
Thanks in advance.
Upvotes: 0
Views: 52
Reputation: 813
Have you considered something like ELMAH It will log any unhandled exceptions to a system of your choice (text file, event log, SQL table, etc).
Upvotes: 1
Reputation: 1316
An exception object won't do the "catching" part. You need to have something else to do that, there are several ways to do this, depending on what type of application you have.
One is explained here:
Or: https://msdn.microsoft.com/en-us/library/24395wz3.aspx
OWIN: https://blog.kloud.com.au/2016/03/23/aspnet-core-tips-and-tricks-global-exception-handling/
Console app: .NET Global exception handler in console application
Upvotes: 1