NuGet.ApplicationInsights.Owin.OwinRequestIdContext.Set C# (CSharp) Method

Set() public static method

public static Set ( string value ) : void
value string
return void
        public static void Set(string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                CallContext.LogicalSetData(RequestTrackingMiddleware.OwinRequestIdKey, value);
            }
        }

Usage Example

コード例 #1
0
        public override async Task Invoke(IOwinContext context)
        {
            var requestId = context.Get <string>(OwinRequestIdKey);

            var requestMethod = context.Request.Method;
            var requestPath   = context.Request.Path.ToString();
            var requestUri    = context.Request.Uri;

            var requestStartDate = DateTimeOffset.Now;
            var stopWatch        = new Stopwatch();

            stopWatch.Start();

            var requestFailed = false;

            try
            {
                OwinRequestIdContext.Set(requestId);

                if (Next != null)
                {
                    await Next.Invoke(context);
                }
            }
            catch (Exception ex)
            {
                requestFailed = true;

                _telemetryClient.TrackException(ex);

                throw;
            }
            finally
            {
                stopWatch.Stop();

                TrackRequest(requestId, requestMethod, requestPath, requestUri,
                             context.Response?.StatusCode ?? 0, requestFailed, requestStartDate, stopWatch.Elapsed);

                OwinRequestIdContext.Clear();
            }
        }
OwinRequestIdContext