public static string Format(LoggingEvent loggingEvent) { var message = new FormattedMessage { Time = loggingEvent.TimeStamp.ToString(CultureInfo.InvariantCulture), Message = loggingEvent.RenderedMessage, Parameters = loggingEvent.Properties["Parameters"] as string, QueryString = loggingEvent.Properties["QueryString"] as string, Referrer = loggingEvent.Properties["Referrer"] as string, Server = loggingEvent.Properties["Server"] as string, Url = loggingEvent.Properties["Url"] as string, UserAgent = loggingEvent.Properties["UserAgent"] as string, IpAddress = loggingEvent.Properties["IPAddress"] as string, RequestHeaders = loggingEvent.Properties["RequestHeaders"] as string, RequestMethod = loggingEvent.Properties["RequestMethod"] as string, ResponseHeaders = loggingEvent.Properties["ResponseHeaders"] as string, StatusCode = Convert.ToInt32(loggingEvent.Properties["StatusCode"]), RequestBody = loggingEvent.Properties["RequestBody"] as string, ResponseBody = loggingEvent.Properties["ResponseBody"] as string, UserName = loggingEvent.Identity }; var exception = loggingEvent.Properties["Exception"] as LoggableException; if (exception != null) { message.SqlErrorMessages = string.IsNullOrEmpty(message.Parameters) ? string.Empty : exception.Message; message.Source = exception.Source; message.StackTrace = exception.StackTrace; message.TargetSite = exception.TargetSite.IfNotNull(x => x.ToString()); message.InnerException = exception.InnerException; } if (loggingEvent.Properties.Contains("ExceptionMessage")) { message.ExceptionMessage = loggingEvent.Properties["ExceptionMessage"].ToString(); } if (loggingEvent.Properties.Contains("ErrorCode")) { message.ErrorCode = (int)loggingEvent.Properties["ErrorCode"]; } return(ExceptionLogFormatter.FormatMessage(message)); }
/// <summary> /// Base S3 Retrieval method; returns the contents of the file in string format. /// </summary> /// <param name="request">A GetObjectRequest containing BucketName and Key values</param> /// <returns></returns> public virtual async Task <string> GetObject(GetObjectRequest request) { string content = string.Empty; try { using (GetObjectResponse response = await S3Client.GetObjectAsync(request)) { using (Stream responseStream = response.ResponseStream) { using (var reader = new StreamReader(response.ResponseStream)) { if (response.HttpStatusCode != HttpStatusCode.OK) { // do what here? log warning once I get CloudWatch or equivalent set up } content = await reader.ReadToEndAsync(); } } } } catch (AmazonS3Exception s3Ex) { Logger.Log(ExceptionLogFormatter.FormatExceptionLogMessage(request, s3Ex)); content = null; } catch (Exception ex) { Logger.Log(ExceptionLogFormatter.FormatExceptionLogMessage(ex)); content = null; } return(content); }