Logging to elmah.io from SvelteKit
To log all errors from a SvelteKit application, install the elmah.io.javascript
npm package as described in Logging from JavaScript. Then add the following code to the hooks.client.js
file. If the file does not exist, make sure to create it in the src
folder since SvelteKit will automatically load it from there.
import Elmahio from 'elmah.io.javascript';
var logger = new Elmahio({
apiKey: 'API_KEY',
logId: 'LOG_ID'
});
/** @type {import('@sveltejs/kit').HandleClientError} */
export function handleError({ error, event }) {
if (error && error.message) {
logger.error(error.message, error);
} else {
logger.error('Error in application', error);
}
}
When launching your SvelteKit app, elmah.io is configured and all errors happening in the application are logged. For now, elmah.io.javascript
only supports SvelteKit apps running inside the browser, why implementing the HandleServerError
is not supported.
Check out the elmahio-sveltekit sample for some real working code.
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