Example #1
0
        public static void AddOperation(ResourceExecutingContext context, string serviceComponent)
        {
            var actionDescriptor = (ControllerActionDescriptor)context.ActionDescriptor;

            var operationData = OperationData.CreateGeneric(serviceComponent, actionDescriptor.ActionName);

            Operation operation = Logger.StartOperation(operationData);

            operation.AddProperty("HttpRequestPort", context.HttpContext.Request.Host.Port ?? -1);
            operation.AddProperty("HttpRequestIsHttps", context.HttpContext.Request.IsHttps);

            // Set CorrelationId and traffic source at Task level such that it will be available to all downstream operations in the context of the request
            Logger.SetCorrelationId(GetCorrolationId(context.HttpContext.Request.Headers));

            if (context.HttpContext.Request.Headers.TryGetValue(
                    HttpHeader.TestTrafficToken,
                    out StringValues trafficSourceString))
            {
                Logger.SetTrafficSource(trafficSourceString);
            }

            // If we are expecting failure (in case of negative test), we won't log this operation as failed
            if (context.HttpContext.Request.Headers.ContainsKey(HttpHeader.ExpectingFail))
            {
                operation.AddProperty(HttpHeader.ExpectingFail, "true");
                operation.ExpectedToFail = true;
            }

            context.HttpContext.Items.Add(OperationPropertyName, operation);
        }
Example #2
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     using (var operation =
                Logger.StartOperation(OperationData.CreateGeneric(this.component, "Configure")))
     {
         operation.Run(() => { this.ConfigureCore(app, env); });
     }
 }
Example #3
0
 public void ConfigureServices(IServiceCollection services)
 {
     using (var operation =
                Logger.StartOperation(OperationData.CreateGeneric(this.component, "ConfigureServices")))
     {
         operation.Run(() =>
         {
             this.ConfigureServicesCore(services);
         });
     }
 }
        public async Task InvokeAsync(HttpContext httpContext)
        {
            try
            {
                await this.next(httpContext).ConfigureAwait(false);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
            {
                Logger.LogFailure(
                    OperationData.CreateGeneric(ServiceComponent.CloudBornWebService.ToString(), "GlobalErrorHandling"),
                    $"Exception {ex.TargetSite.Name} that was not caught in MVC filters",
                    ErrorLevel.Critical,
                    ex);

                httpContext.Response.ContentType = "application/json";
                httpContext.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }