Skip to content

Commit

Permalink
WIP - Log exceptions from asp.net diagnostics :)
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Jun 20, 2016
1 parent 7021e45 commit de41e30
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Exceptionless.AspNetCore;
using Exceptionless.Models;
using Exceptionless.Models.Data;
using Exceptionless.Plugins.Default;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Exceptionless {
public static class ExceptionlessExtensions {
Expand All @@ -18,6 +20,9 @@ public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app,
client.Configuration.AddPlugin<ExceptionlessAspNetCorePlugin>();
client.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
//client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();

var diagnosticListener = app.ApplicationServices.GetRequiredService<DiagnosticListener>();
diagnosticListener?.SubscribeWithAdapter(new ExceptionlessDiagnosticListener(client));

return app.UseMiddleware<ExceptionlessMiddleware>(client);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Platforms/Exceptionless.AspNetCore/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-rc2-final",
"Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc2-final",
"Microsoft.Net.Http.Headers": "1.0.0-rc2-final"
"Microsoft.Extensions.DiagnosticAdapter": "1.0.0-rc2-final",
"Microsoft.Net.Http.Headers": "1.0.0-rc2-final",
"System.Diagnostics.DiagnosticSource": "4.0.0-rc2-24027"
},
"frameworks": {
"netstandard1.5": {
Expand Down

0 comments on commit de41e30

Please sign in to comment.