Skip to content

Commit 8338da4

Browse files
committed
Updated readme and sample to use services.AddHttpContextAccessor()
1 parent 2cdf4b9 commit 8338da4

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

samples/Exceptionless.SampleAspNetCore/Controllers/ValuesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ValuesController : Controller {
99
// GET api/values
1010
[HttpGet]
1111
public Dictionary<string, string> Get() {
12-
ExceptionlessClient.Default.CreateLog("ValuesController", "Getting results", LogLevel.Info).SetHttpContext(HttpContext).Submit();
12+
ExceptionlessClient.Default.CreateLog("ValuesController", "Getting results", LogLevel.Info).Submit();
1313
throw new Exception($"Random AspNetCore Exception: {Guid.NewGuid()}");
1414
}
1515
}

samples/Exceptionless.SampleAspNetCore/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void ConfigureServices(IServiceCollection services) {
2323
.AddConfiguration(Configuration.GetSection("Logging"))
2424
.AddDebug()
2525
.AddConsole());
26+
services.AddHttpContextAccessor();
2627
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
2728
}
2829

src/Platforms/Exceptionless.AspNetCore/ExceptionlessAspNetCorePlugin.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99
namespace Exceptionless.AspNetCore {
1010
[Priority(90)]
1111
public class ExceptionlessAspNetCorePlugin : IEventPlugin {
12-
IHttpContextAccessor _httpContextAccessor;
13-
14-
public ExceptionlessAspNetCorePlugin()
15-
: this(null) {
16-
17-
}
18-
19-
public ExceptionlessAspNetCorePlugin(IHttpContextAccessor httpContextAccessor) {
12+
private readonly IHttpContextAccessor _httpContextAccessor;
13+
14+
public ExceptionlessAspNetCorePlugin(IHttpContextAccessor httpContextAccessor = null) {
2015
_httpContextAccessor = httpContextAccessor;
2116
}
2217

@@ -38,8 +33,7 @@ public void Run(EventPluginContext context) {
3833

3934
try {
4035
ri = httpContext.GetRequestInfo(context.Client.Configuration);
41-
}
42-
catch (Exception ex) {
36+
} catch (Exception ex) {
4337
context.Log.Error(typeof(ExceptionlessAspNetCorePlugin), ex, "Error adding request info.");
4438
}
4539

src/Platforms/Exceptionless.AspNetCore/readme.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ the following method.
4747

4848
exception.ToExceptionless().Submit()
4949

50-
Please note that ASP.NET Core doesn't have a static http context. If possible, it is recommended
51-
that you set the HttpContext when submitting events. Doing so will allow the request and
52-
user information to be populated. You can do this by calling the SetHttpContext EventBuilder
53-
extension method.
50+
Please note that ASP.NET Core doesn't have a static http context. We recommend registering
51+
the http context accessor. Doing so will allow the request and user information to be populated.
52+
You can do this by calling the AddHttpContextAccessor while configure services.
5453

55-
exception.ToExceptionless().SetHttpContext(ActionContext).Submit()
54+
services.AddHttpContextAccessor()
5655

5756
-------------------------------------
5857
Documentation and Support

0 commit comments

Comments
 (0)