diff --git a/samples/Exceptionless.SampleAspNetCore/Controllers/ValuesController.cs b/samples/Exceptionless.SampleAspNetCore/Controllers/ValuesController.cs index c4c91953..8ec49e12 100644 --- a/samples/Exceptionless.SampleAspNetCore/Controllers/ValuesController.cs +++ b/samples/Exceptionless.SampleAspNetCore/Controllers/ValuesController.cs @@ -9,7 +9,7 @@ public class ValuesController : Controller { // GET api/values [HttpGet] public Dictionary Get() { - ExceptionlessClient.Default.CreateLog("ValuesController", "Getting results", LogLevel.Info).SetHttpContext(HttpContext).Submit(); + ExceptionlessClient.Default.CreateLog("ValuesController", "Getting results", LogLevel.Info).Submit(); throw new Exception($"Random AspNetCore Exception: {Guid.NewGuid()}"); } } diff --git a/samples/Exceptionless.SampleAspNetCore/Startup.cs b/samples/Exceptionless.SampleAspNetCore/Startup.cs index 6d141af9..690c5a40 100644 --- a/samples/Exceptionless.SampleAspNetCore/Startup.cs +++ b/samples/Exceptionless.SampleAspNetCore/Startup.cs @@ -23,6 +23,7 @@ public void ConfigureServices(IServiceCollection services) { .AddConfiguration(Configuration.GetSection("Logging")) .AddDebug() .AddConsole()); + services.AddHttpContextAccessor(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); } diff --git a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs index 52a16ed0..93f12400 100644 --- a/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs +++ b/src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs @@ -9,14 +9,9 @@ namespace Exceptionless.AspNetCore { [Priority(90)] public class ExceptionlessAspNetCorePlugin : IEventPlugin { - IHttpContextAccessor _httpContextAccessor; - - public ExceptionlessAspNetCorePlugin() - : this(null) { - - } - - public ExceptionlessAspNetCorePlugin(IHttpContextAccessor httpContextAccessor) { + private readonly IHttpContextAccessor _httpContextAccessor; + + public ExceptionlessAspNetCorePlugin(IHttpContextAccessor httpContextAccessor = null) { _httpContextAccessor = httpContextAccessor; } @@ -38,8 +33,7 @@ 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/readme.txt b/src/Platforms/Exceptionless.AspNetCore/readme.txt index a65f647a..6e9311b2 100644 --- a/src/Platforms/Exceptionless.AspNetCore/readme.txt +++ b/src/Platforms/Exceptionless.AspNetCore/readme.txt @@ -47,12 +47,11 @@ the following method. exception.ToExceptionless().Submit() -Please note that ASP.NET Core doesn't have a static http context. If possible, it is recommended -that you set the HttpContext when submitting events. Doing so will allow the request and -user information to be populated. You can do this by calling the SetHttpContext EventBuilder -extension method. +Please note that ASP.NET Core doesn't have a static http context. We recommend registering +the http context accessor. Doing so will allow the request and user information to be populated. +You can do this by calling the AddHttpContextAccessor while configure services. -exception.ToExceptionless().SetHttpContext(ActionContext).Submit() +services.AddHttpContextAccessor() ------------------------------------- Documentation and Support