2

I have set Elmah for an ASP.NET MVC 5 project to handle exceptions and save them in database (Oracle).

Now I've encountered a situation where Elmah can fail to log exceptions in database and cause an exception by itself because database being down, connection string changes etc.

I tried this:

try { Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Testing Elmah exception handling")); } catch (Exception ex) { LogException(ex); } 

but LogException(ex) is never executed.

In LogException I have implemented a custom logger that also writes in database.

3
  • 1
    Ideally, you should log the elmah failures in the Windows Event Log. That means, if Elmah fails to write in database, then it should log the elmah exception in Windows log of the server. This is just a fallback scenario. Commented Mar 16, 2018 at 10:14
  • @Nirman Thanks for pointing out to the Windows Event Log. It seems when Elmah has internal exceptions they automatically are written to Windows Event Log and no exception is thrown. That is the reason why my catch block is not hit at all. Commented Mar 16, 2018 at 11:51
  • Glad, it assisted you to find the direction. I thought you may need to explicitly write it in Windows Log, but its been done by default. Commented Mar 16, 2018 at 12:16

1 Answer 1

1

Elmah writes failures in Windows Event logs on server in fallback scenarios. That means, if Elmah fails to write exception/ event in the configuration option you might have selected (i.e., Database, file system, or whatever custom option configuration), it will write to the Windows Event Logs on the server where the application is running.

As an additional note, in case of NLB (Load balance) environments, the exception would be logged in Windows event log of one of the servers from where a particular request is being served, and not all server where the application is running).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.