0

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.

Talha
  • 903
  • 8
  • 31
GreenGeckoZA
  • 21
  • 2
  • 7
  • 1
    Check configuration are proper and you are calling the xmlconfiguration http://stackoverflow.com/questions/16766236/log4net-only-works-when-xmlconfigurator-configure-is-called – Mahesh Malpani Feb 05 '16 at 11:51
  • can you log anything with log4net? – fire in the hole Feb 05 '16 at 13:41
  • What does your web.config look like? How about the appender? Are you logging to a database, text file, etc? We need more information. Also @Sheagorath yes, you can log anything. – BBauer42 Feb 12 '16 at 18:57
  • Did you get this to work? Another thing you could try is to change the bufferSize to 1. – BBauer42 Feb 29 '16 at 18:19

0 Answers0