private void SendLogAction(LoggingEvent loggingEvent) { //we should always format event in the same thread as //many properties used in the event are associated with the current thread //like threadname, ndc stacks, threadcontent properties etc. //initializing a string for the formatted log string formattedMessage; //if Layout is null then format the log from the Loggly Client if (Layout == null) { // TODO: Adjust Formatter to optimally suit Google Cloud Logging. Formatter.AppendAdditionalLoggingInformation(_config, loggingEvent); formattedMessage = Formatter.ToJson(loggingEvent); } else { //formattedMessage = Formatter.ToJson(RenderLoggingEvent(loggingEvent), loggingEvent.TimeStamp); formattedMessage = RenderLoggingEvent(loggingEvent); } //var y= RenderLoggingEvent(loggingEvent); //var z = loggingEvent.RenderedMessage; var formattedLoggingEvent = new FormattedLoggingEvent(loggingEvent, formattedMessage); ThreadPool.QueueUserWorkItem(x => _client.Send(new FormattedLoggingEvent[] { formattedLoggingEvent })); }
private LogEntry LoggingEventToLogEntry(FormattedLoggingEvent formattedLoggingEvent) { var loggingEvent = formattedLoggingEvent.LoggingEvent; return(new LogEntry() { //TextPayload = message, TextPayload = formattedLoggingEvent.FormattedMessage, //StructPayload = new Dictionary<string, object> { {"status", "200"} }, Metadata = new LogEntryMetadata { ProjectId = _config.MetadataProjectsId, ServiceName = _config.MetadataServiceName, Region = _config.MetadataRegion, Zone = _config.MetadataZone, Severity = LevelToSeverity(loggingEvent.Level), Timestamp = loggingEvent.TimeStamp.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), UserId = "", //Labels = PropertiesToLabels(loggingEvent.Properties), //Labels = new Dictionary<string, string> { {"status","200"}, {"protocol","HTTP"} } } }); }