Skip to content

Pushes unhandled errors in ASP.Net applications directly to a Slack channel

License

Notifications You must be signed in to change notification settings

WiredUK/Wired.SlackErrors

Repository files navigation

Wired.SlackErrors

Push unhandled errors in an ASP.Net project directly into a Slack channel.

Documentation

Setting up is nice and easy. First you need to get a URL from your Slack channel.

  1. Open up the custom integration builder from your Slack app, the URL will be something like this:

    https://<your-app-name>.slack.com/apps/build/custom-integration
    
  2. Create a new Incoming WebHook.

  3. Choose the channel you want to post to and click Add.

  4. Note the WebHook URL, this is what you need in all the web applications that you want to post into this channel.

  5. Install the Wired.SlackErrors library into your app by manually referencing the DLL or adding the Nuget package (adding to Nuget is a TODO for me!)

  6. In your web.config file, you need to add the following line into the configSections element. This registers the configuration element in the next step

  7. Add in the following configuration element:

    <slackErrors appName="<website name>">
        <channels>
            <add name="<channel name>"
                 postUrl="<webhoook-url>" />
        </channels>
    </slackErrors>
    
  8. Make sure to replace the appName (this is posted into teh Slack channel so you can easily identify the error source), the channel name (this is only useful for you to identify where the URL is posting to) and the postUrl (as given above in the Slack configuration)

That's all that is needed. Now any unhandled errors (those pesky things that cause your ASP.Net application to show the yellow screen of death) will get posted to Slack.

Filtering

It is possible to filter the errors that get posted, this is especially useful if you are only interested in specific error type or you're looking for specific text in the stack trace. You can filter on exception type or stack trace, for example this will ensure that only NullReferenceException exceptions are sent to Slack:

<add name="Website Errors Channel" 
     postUrl="https://hooks.slack.com/services/..." 
     typeFilter="System\.NullReferenceException" />

If you want to filter on stack trace, use traceFilter instead:

<add name="Website Errors Channel" 
     postUrl="https://hooks.slack.com/services/..." 
     traceFilter="......" />

Both traceFilter and traceFilter use regular expressions to match. So for example if you only wanted to see SqlException and ApplicationException exceptions, you can do this:

<add name="Website Errors Channel" 
     postUrl="https://hooks.slack.com/services/..." 
     typeFilter="System\.(Sql|Application)Exception" />

You can use filtering to post different exception types to different channels, so if you wanted all SqlException in one channel and all ApplicationException in another, just add two channels with specific filters:

<add name="Application Errors Channel" 
     postUrl="https://hooks.slack.com/services/...URL2" 
     typeFilter="System\.ApplicationException" />
<add name="SQL Errors Channel" 
     postUrl="https://hooks.slack.com/services/...URL1" 
     typeFilter="System\.SqlException" />

About

Pushes unhandled errors in ASP.Net applications directly to a Slack channel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published