Skip to content

Instantly share code, notes, and snippets.

@andreabalducci
Created May 24, 2013 06:56
Show Gist options
  • Save andreabalducci/5641743 to your computer and use it in GitHub Desktop.
Save andreabalducci/5641743 to your computer and use it in GitHub Desktop.
Elmah Pipeline Module for Signalr
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using Elmah;
using Microsoft.AspNet.SignalR.Hubs;
namespace App.Website.Support.SignalrPipelineExtensions
{
public class ElmahPipelineModule : HubPipelineModule
{
private static bool RaiseErrorSignal(Exception e)
{
var context = HttpContext.Current;
if (context == null)
return false;
var signal = ErrorSignal.FromContext(context);
if (signal == null)
return false;
signal.Raise(e, context);
return true;
}
private static void LogException(Exception e)
{
var context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(e, context));
}
protected override void OnIncomingError(Exception ex, IHubIncomingInvokerContext context)
{
var exception = ex;
if (ex is TargetInvocationException)
{
exception = ex.InnerException;
}
else if (ex is AggregateException)
{
exception = ex.InnerException;
}
if(!RaiseErrorSignal(exception))
LogException(exception);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment