Skip to content

Commit

Permalink
Add RequestTraceMiddleware in Hosting project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Codespilot committed Jul 5, 2023
1 parent 4f005a2 commit f1e001b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static IServiceCollection AddUserPrincipal(this IServiceCollection servic
}

/// <summary>
///
/// Add <see cref="Serilog.ILogger"/> as logging provider.
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
Expand All @@ -174,7 +174,7 @@ public static IServiceCollection AddSerilog(this IServiceCollection services)
}

/// <summary>
///
/// Get hosting environment from <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
Expand Down
1 change: 1 addition & 0 deletions Source/Euonia.Hosting/HostingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex
{
base.OnApplicationInitialization(context);
var app = context.GetApplicationBuilder();
app.UseMiddleware<RequestTraceMiddleware>();
app.Use(async (httpContext, next) =>
{
var accessor = httpContext.RequestServices.GetService<IServiceAccessor>();
Expand Down
20 changes: 20 additions & 0 deletions Source/Euonia.Hosting/Middlewares/RequestTraceMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Http;

namespace Nerosoft.Euonia.Hosting;

public class RequestTraceMiddleware
{
private readonly RequestDelegate _next;

public RequestTraceMiddleware(RequestDelegate next)
{
_next = next;
}

public async Task InvokeAsync(HttpContext context)
{
context.Response.Headers.Add("x-request-trace-id", context.TraceIdentifier);

await _next(context);
}
}

0 comments on commit f1e001b

Please sign in to comment.