Created
May 24, 2013 06:56
-
-
Save andreabalducci/5641743 to your computer and use it in GitHub Desktop.
Elmah Pipeline Module for Signalr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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