NuGet npm Samples

Logging to elmah.io from React

To log all errors from a React application, install the elmah.io.javascript npm package as described in Logging from JavaScript. Then modify the index.js or index.tsx file:

// ...
import Elmahio from 'elmah.io.javascript'; 

new Elmahio({
  apiKey: 'API_KEY',
  logId: 'LOG_ID'
});

// After this the ReactDOM.render etc. will be included

When launching your React app, elmah.io is configured and all errors happening in the application are logged.

Check out the elmahio-react and elmahio-react-typescript samples for some real working code.

React have a known bug/feature in DEV mode where errors are submitted twice. For better error handling in React, you should look into Error Boundaries.


This article was brought to you by the elmah.io team. elmah.io is the best error management system for .NET web applications. We monitor your website, alert you when errors start happening, and help you fix errors fast.

See how we can help you monitor your website for crashes Monitor your website