in src/Hosting.Services.Web/ApplicationBuilderExtensions.cs [51:113]
public static IApplicationBuilder UseActivityEnrichmentMiddleware(this IApplicationBuilder builder) =>
builder.UseMiddleware<ActivityEnrichmentMiddleware>();
/// <summary>
/// Add middleware that adds Omex headers to responses, like MachineId and BuildVersion
/// </summary>
public static IApplicationBuilder UseResponseHeadersMiddleware(this IApplicationBuilder builder) =>
builder.UseMiddleware<ResponseHeadersMiddleware>();
/// <summary>
/// Add middleware user identity middleware to add user hash to correlation
/// </summary>
public static IApplicationBuilder UseUserHashIdentiyMiddleware(this IApplicationBuilder builder) =>
builder.UseMiddleware<UserHashIdentityMiddleware>();
/// <summary>
/// Add middleware that adds Omex headers to responses, like MachineId and BuildVersion
/// </summary>
[Obsolete("Use it only if you need to communicate with services that use old correlation", false)]
public static IApplicationBuilder UseObsoleteCorrelationHeadersMiddleware(this IApplicationBuilder builder) =>
builder.UseMiddleware<ObsoleteCorrelationHeadersMiddleware>();
/// <summary>
/// Adds the default exception handling logic that will display a developer exception page in develop and a short message during deployment
/// </summary>
public static IApplicationBuilder UseOmexExceptionHandler(this IApplicationBuilder builder, IHostEnvironment environment) =>
builder.UseOmexExceptionHandler(environment.IsDevelopment());
/// <summary>
/// Adds the default exception handling logic that will display a developer exception page in develop and a short message during deployment
/// </summary>
public static IApplicationBuilder UseOmexExceptionHandler(this IApplicationBuilder builder, bool isDevelopment)
{
if (isDevelopment)
{
builder.UseDeveloperExceptionPage();
}
else
{
builder.UseExceptionHandler(appError =>
{
appError.Run(context =>
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
context.Response.ContentType = "application/json";
IExceptionHandlerFeature? contextFeature = context.Features.Get<IExceptionHandlerFeature>();
Dictionary<string, string> errorDict = new Dictionary<string, string>
{
{ "Message", "Internal Server Error" },
{ "ErrorMessage", contextFeature?.Error?.Message ?? string.Empty },
{ "RequestId", Activity.Current?.Id ?? context.TraceIdentifier },
{ "Suggestion", "For local debugging, set ASPNETCORE_ENVIRONMENT environment variable to 'Development' and restart the application" }
};
return context.Response.WriteAsync(JsonSerializer.Serialize(errorDict));
});
});
}
return builder;
}