Search code examples
azureazure-application-insightselmah

Can I send Elmah erros details to ApplicationInsights?


I have an old application which I used Elmah to aggregate exceptions and save data to disk/db.

Today, I start using Azure Monitor with Application insights SDK to monitor my services, so that I'm asking how can I keep using Elmah and send my application error details to Azure monitor too.

Thanks in advance!


Solution

  • A simple but effective hack is to use the Error Filter feature to intercept the exceptions routed to ELMAH and send them to App Insights as well:

    void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
    {
         new TelemetryClient().TrackException(e.Exception);
    }
    

    Not that you should reuse an instance of TelemetryClient but this code is just to give you an idea of the approach.