diff --git a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs index 77ad12eb..52a16ed0 100644 --- a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs +++ b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs @@ -8,9 +8,23 @@ namespace Exceptionless.AspNetCore { [Priority(90)] - internal class ExceptionlessAspNetCorePlugin : IEventPlugin { + public class ExceptionlessAspNetCorePlugin : IEventPlugin { + IHttpContextAccessor _httpContextAccessor; + + public ExceptionlessAspNetCorePlugin() + : this(null) { + + } + + public ExceptionlessAspNetCorePlugin(IHttpContextAccessor httpContextAccessor) { + _httpContextAccessor = httpContextAccessor; + } + public void Run(EventPluginContext context) { var httpContext = context.ContextData.GetHttpContext(); + if (httpContext == null && _httpContextAccessor != null) + httpContext = _httpContextAccessor.HttpContext; + var serializer = context.Client.Configuration.Resolver.GetJsonSerializer(); if (context.Client.Configuration.IncludeUserName) AddUser(context, httpContext, serializer); @@ -24,7 +38,8 @@ public void Run(EventPluginContext context) { try { ri = httpContext.GetRequestInfo(context.Client.Configuration); - } catch (Exception ex) { + } + catch (Exception ex) { context.Log.Error(typeof(ExceptionlessAspNetCorePlugin), ex, "Error adding request info."); } diff --git a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessDiagnosticListener.cs b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessDiagnosticListener.cs index 3c2914e1..5108b513 100644 --- a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessDiagnosticListener.cs +++ b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessDiagnosticListener.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.DiagnosticAdapter; namespace Exceptionless.AspNetCore { - internal sealed class ExceptionlessDiagnosticListener { + public sealed class ExceptionlessDiagnosticListener { private readonly ExceptionlessClient _client; public ExceptionlessDiagnosticListener(ExceptionlessClient client) { diff --git a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs index f765f770..1839f0df 100644 --- a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs +++ b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessExtensions.cs @@ -18,8 +18,12 @@ public static IApplicationBuilder UseExceptionless(this IApplicationBuilder app, if (client == null) client = ExceptionlessClient.Default; + // Can be registered in Startup.ConfigureServices via services.AddHttpContextAccessor(); + // this is necessary to obtain Session and Request information outside of ExceptionlessMiddleware + var contextAccessor = app.ApplicationServices.GetService(); + client.Startup(); - client.Configuration.AddPlugin(); + client.Configuration.AddPlugin(new ExceptionlessAspNetCorePlugin(contextAccessor)); client.Configuration.AddPlugin(); //client.Configuration.Resolver.Register(); diff --git a/src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs b/src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs index 044f6fa8..3bc298b1 100644 --- a/src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs +++ b/src/Platforms/Exceptionless.AspNetCore/RequestInfoCollector.cs @@ -12,7 +12,7 @@ using System.Text; namespace Exceptionless.AspNetCore { - internal static class RequestInfoCollector { + public static class RequestInfoCollector { private const int MAX_BODY_SIZE = 50 * 1024; public static RequestInfo Collect(HttpContext context, ExceptionlessConfiguration config) { if (context == null)