From ed94ea485d44d1606e0dfdc01d3e231b3fbae95e Mon Sep 17 00:00:00 2001 From: Warren Buckley Date: Tue, 11 Sep 2018 09:04:29 +0100 Subject: [PATCH] Gets the same HttpRequestId from the Enricher to use in the message template for text log files for begin & end request verbose logs --- src/Umbraco.Web/UmbracoModule.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index b79a697e39..d0ad7568e0 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -21,6 +21,7 @@ using Umbraco.Core.Security; using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; +using Umbraco.Core.Logging.Serilog.Enrichers; namespace Umbraco.Web { @@ -558,8 +559,12 @@ namespace Umbraco.Web { var httpContext = ((HttpApplication) sender).Context; - //Create a new Request ID/GUID - requestId = Guid.NewGuid(); + var httpRequestId = Guid.Empty; + HttpRequestIdEnricher.TryGetCurrentHttpRequestId(out httpRequestId); + + Logger.Verbose("Begin request [{HttpRequestId}]: {RequestUrl}", + httpRequestId, + httpContext.Request.Url); BeginRequest(new HttpContextWrapper(httpContext)); }; @@ -603,8 +608,12 @@ namespace Umbraco.Web if (UmbracoContext.Current != null) { + var httpRequestId = Guid.Empty; + HttpRequestIdEnricher.TryGetCurrentHttpRequestId(out httpRequestId); + Logger.Verbose( - "Request: {RequestUrl} took {Duration}ms", + "End request [{HttpRequestId}]: {RequestUrl} took {Duration}ms", + httpRequestId, httpContext.Request.Url, DateTime.Now.Subtract(UmbracoContext.Current.ObjectCreated).TotalMilliseconds); }