Skip to content

Instantly share code, notes, and snippets.

@AlbertoMonteiro
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save AlbertoMonteiro/8c11af6cb65f775e42d4 to your computer and use it in GitHub Desktop.

Select an option

Save AlbertoMonteiro/8c11af6cb65f775e42d4 to your computer and use it in GitHub Desktop.
Rollbar
filters.Add(new RollbarMvcExceptionFilter());
kernel.BindFilter(FilterScope.Global, 10).InSingletonScope();
public class RollbarMvcExceptionFilter : IExceptionFilter
{
RollbarClient client = new RollbarClient();
public void OnException(ExceptionContext filterContext)
{
if (filterContext.ExceptionHandled)
return;
client.SendException(filterContext.Exception);
}
}
public class RollbarWebApiExceptionFilter : IExceptionFilter
{
RollbarClient client = new RollbarClient();
public bool AllowMultiple
{
get { return false; }
}
public async Task ExecuteExceptionFilterAsync(HttpActionExecutedContext context, CancellationToken cancelToken)
{
await Task.Factory.StartNew(() => client.SendException(context.Exception), cancelToken);
}
}
<configuration>
<appSettings>
<add key="Rollbar.AccessToken" value="YOUR_TOKEN_HERE"/>
<add key="Rollbar.Environment" value="developement"/>
</appSettings>
</configuration>
<configuration>
<appSettings>
<add key="Rollbar.Environment" value="production" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
config.Filters.Add(new RollbarWebApiExceptionFilter());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment