public void LogExternalAPIAccess(Guid requestId, string service, string operation,
                                         ServiceConsumptionOptions options, object response, HttpStatusCode status,
                                         TimeSpan processingTime, bool throwOnError = false, bool cachedResponse = false)
        {
            if (!_initialized)
            {
                return;
            }

            var message = LogMessage.CreateMessage(requestId, options, service, operation, response, status, processingTime, cachedResponse);

            Log("external", $"{service}.{operation}", message, throwOnError);
        }
        public static LogMessage CreateMessage(Guid requestId,
                                               ServiceConsumptionOptions options,
                                               string service, string operation,
                                               object responseMessage,
                                               HttpStatusCode statusCode,
                                               TimeSpan processingTime,
                                               bool cachedResponse)
        {
            var logMessage = new LogMessage
            {
                Service       = service,
                Operation     = operation,
                StatusCode    = (int)statusCode,
                RequestMethod = options.Verb.ToString(),
                RequestPath   = options.Url,
                RequestUri    = options.Url,
                Message       = statusCode.ToString(),
                ElapsedMsecs  = processingTime.TotalMilliseconds,
                CacheHit      = cachedResponse,
                RequestId     = requestId,
                //IP = GetClientIpAddress(request),
                Timestamp = DateTime.UtcNow,
                Username  = HttpContext.Current?.User?.Identity.IsAuthenticated == true
                    ? HttpContext.Current.User.Identity.Name
                    : "Anonymous",
                Request = new JObject {
                    ["ConsumerRequest"] = JToken.FromObject(options)
                },
                Response = responseMessage
            };

            if (responseMessage != null && IsSimple(responseMessage.GetType()))
            {
                logMessage.Response = new JObject {
                    ["Data"] = JToken.FromObject(responseMessage)
                };
            }

            var requestMessage = HttpContext.Current?.Items["MS_HttpRequestMessage"] as HttpRequestMessage;

            if (requestMessage?.Properties["exposed-service-requestId"] != null)
            {
                logMessage.ExposedApiCorrelationId = (Guid)requestMessage?.Properties["exposed-service-requestId"];
            }

            return(logMessage);
        }
 public void LogExternalAPIAccess(Guid requestId, string service, string operation, ServiceConsumptionOptions options, object response, HttpStatusCode status, TimeSpan processingTime, bool throwOnError = false, bool cachedResponse = false)
 {
     throw new NotImplementedException();
 }
 public void LogExternalAPIAccess(Guid requestId, string service, string operation, ServiceConsumptionOptions options, object response, HttpStatusCode status, TimeSpan processingTime, bool throwOnError = false, bool cachedResponse = false)
 {
     _logger.LogInformation($"{requestId},{service},{operation},{processingTime},{status}");
 }