Skip to content

Commit

Permalink
Changed ExceptionlessAspNetCorePlugin to allow for retrieving HttpCon…
Browse files Browse the repository at this point in the history
…text via IHttpContextAccessor. (#205)

Made ExceptionlessAspNetCorePlugin, ExceptionlessDiagnosticListener, and RequestInfoCollector public classes.
  • Loading branch information
moogle001 authored and niemyjski committed Feb 6, 2019
1 parent c03b5d3 commit 2cdf4b9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHttpContextAccessor>();

client.Startup();
client.Configuration.AddPlugin<ExceptionlessAspNetCorePlugin>();
client.Configuration.AddPlugin(new ExceptionlessAspNetCorePlugin(contextAccessor));
client.Configuration.AddPlugin<IgnoreUserAgentPlugin>();
//client.Configuration.Resolver.Register<ILastReferenceIdManager, WebLastReferenceIdManager>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2cdf4b9

Please sign in to comment.