-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Log exceptions from asp.net diagnostics :)
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/Platforms/Exceptionless.AspNetCore/ExceptionlessDiagnosticListener.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Exceptionless.Plugins; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DiagnosticAdapter; | ||
|
||
namespace Exceptionless.AspNetCore { | ||
internal sealed class ExceptionlessDiagnosticListener { | ||
private readonly ExceptionlessClient _client; | ||
public ExceptionlessDiagnosticListener(ExceptionlessClient client) { | ||
_client = client; | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.Diagnostics.HandledException")] | ||
public void OnDiagnosticHandledException(HttpContext context, Exception ex) { | ||
var contextData = new ContextData(); | ||
contextData.SetSubmissionMethod("Microsoft.AspNetCore.Diagnostics.UnhandledException"); | ||
contextData.Add(nameof(HttpContext), context); | ||
|
||
ex.ToExceptionless(contextData, _client).Submit(); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.Diagnostics.UnhandledException")] | ||
public void OnDiagnosticUnhandledException(HttpContext context, Exception ex) { | ||
var contextData = new ContextData(); | ||
contextData.MarkAsUnhandledError(); | ||
contextData.SetSubmissionMethod("Microsoft.AspNetCore.Diagnostics.HandledException"); | ||
contextData.Add(nameof(HttpContext), context); | ||
|
||
ex.ToExceptionless(contextData, _client).Submit(); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.Hosting.UnhandledException")] | ||
public void OnHostingUnhandledException(HttpContext context, Exception ex) { | ||
var contextData = new ContextData(); | ||
contextData.MarkAsUnhandledError(); | ||
contextData.SetSubmissionMethod("Microsoft.AspNetCore.Hosting.UnhandledException"); | ||
contextData.Add(nameof(HttpContext), context); | ||
|
||
ex.ToExceptionless(contextData, _client).Submit(); | ||
} | ||
|
||
[DiagnosticName("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException")] | ||
public void OnMiddlewareException(Exception ex, string name) { | ||
var contextData = new ContextData(); | ||
contextData.MarkAsUnhandledError(); | ||
contextData.SetSubmissionMethod(name); | ||
|
||
ex.ToExceptionless(contextData, _client).Submit(); | ||
} | ||
} | ||
} |
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
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