Skip to content

Commit

Permalink
Updated readme and sample to use services.AddHttpContextAccessor()
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Feb 6, 2019
1 parent 2cdf4b9 commit 8338da4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ValuesController : Controller {
// GET api/values
[HttpGet]
public Dictionary<string, string> 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()}");
}
}
Expand Down
1 change: 1 addition & 0 deletions samples/Exceptionless.SampleAspNetCore/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void ConfigureServices(IServiceCollection services) {
.AddConfiguration(Configuration.GetSection("Logging"))
.AddDebug()
.AddConsole());
services.AddHttpContextAccessor();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

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

Expand All @@ -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.");
}

Expand Down
9 changes: 4 additions & 5 deletions src/Platforms/Exceptionless.AspNetCore/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8338da4

Please sign in to comment.