Creating Rules to Perform Actions on Messages
elmah.io comes with a great rule engine for performing various actions when messages are logged in your log.
This guide is also available as a short video tutorial here:
The rule engine is located beneath each log on the log settings page:
A rule consists of three parts: a title, a query, and an action.
The title should be a short text explaining what this rule does. We don't use the title for anything, so please write something that helps you identify rules and keep them apart.
The query should contain either a full-text search string or a Lucene query. When new messages are logged, the message is matched up against all queries registered on that log. If and only if a message matches a query, the action registered on the rule is performed.
As mentioned above, the action part of a rule is executed when a message matches the query specified in the same rule. An action can be one of six types: Ignore, Hide, Mail, HTTP Request, Mark as bot, and Mark as fixed. To illustrate how to use each action type, here are six examples of useful rules.
Ignore errors with an HTTP status code of 400
Note
Be aware that Ignore rules are only meant as a temporary way of ignoring messages. In case you want to permanently ignore one or more log messages, use client-side filtering as explained in the documentation for each client integration. In addition, there's a client-side filtering help dialog available on the log message details toolbar. Ignoring a large number of messages with Ignore rules will slow down your application logging, use unnecessary network bandwidth, and risk hitting the elmah.io API request limit.
To ignore all messages with an HTTP status code of 400, you would need to set up the following:
Title | Query | Then |
---|---|---|
Ignore 400s | statusCode:400 |
Ignore |
The rule would look like this in the UI:
Hide warnings
To hide all messages with a severity of Warning
, you would need to set up the following:
Title | Query | Then |
---|---|---|
Hide Warnings | severity:Warning |
Hide |
The rule would look like this in the UI:
Send an email on all messages containing a word
To send an email on all messages containing the word billing somewhere, you would need to set up the following:
Title | Query | Then |
---|---|---|
Mail on billing | billing |
The rule would look like this in the UI:
Make an HTTP request on all new and fatal messages
To make an HTTP request on every new message with a severity of Fatal
, you would need to set up the following:
Title | Query | Then |
---|---|---|
Request on new fatal | isNew:true AND severity:Fatal |
HTTP |
The rule would look like this in the UI:
Mark log messages from IP as bot
To mark log messages generated from an IP range with the isBot
flag, you would need to set up the following:
Title | Query | Then |
---|---|---|
Mark IP as bot | remoteAddr:172.253.63.* |
Mark as bot |
The rule would look like this in the UI:
Mark Debug log messages as fixed
To mark log messages with a severity of Debug
as fixed, you would need to set up the following:
Title | Query | Then |
---|---|---|
Mark Debug as fixed | severity:Debug |
Mark as fixed |
The rule would look like this in the UI:
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