I have a custom exception which I want to log with log4net. Instead of logging the exception in my catch clause, is there a way I can actually log the error from within my custom exception. I attach a code snipped of my custom exception class.
static ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Int32 _clientId;
private String _recordType;
private Int32 _recordId;
private String _message;
public RecordNotFoundException() { }
public RecordNotFoundException(Int32 ClientId, Int32 RecordId, String RecordType) : base()
{
_clientId = ClientId;
_recordType = RecordType;
_message = String.Format("Record not found. Client Id: {0} | Record Id: {1} | Record Type: {2}", ClientId, RecordId, RecordType);
log.Error(_message);
}
I put the log function in my constructor. It is calling it but nothing gets logged.
Thanks in advance.