protected override async Task EmitBatchAsync(IEnumerable <LogEvent> events) { var mapitomLogEvents = events.ToList().ConvertAll(logEvent => { var mapitomLogEvent = new MapitomLogEvent { LogLevel = (LogLevel)Enum.Parse(typeof(LogLevel), $"{logEvent.Level}"), Message = logEvent.RenderMessage(_formatProvider), DateTimeUtc = logEvent.Timestamp.DateTime.ToUniversalTime(), Properties = logEvent.Properties.ToDictionary(p => p.Key, p => p.Value.ToString()) }; if (logEvent.Exception != null) { mapitomLogEvent.Properties.Add("ExceptionMessage", logEvent.Exception.Message); mapitomLogEvent.Properties.Add("ExceptionType", logEvent.Exception.GetType()?.Name); mapitomLogEvent.Properties.Add("Stacktrace", logEvent.Exception.StackTrace); } return(mapitomLogEvent); }); var mapitomLogData = new MapitomLogData { Key = _staticKey, ApplicationKey = _applicationKey, MapitomLogEvents = mapitomLogEvents }; var json = ConvertToJson(mapitomLogData); var uri = "/api/logger/logs"; await _httpClient.PostAsync(uri, new StringContent(json, Encoding.UTF8, "application/json")); }
private string ConvertToJson(MapitomLogData mapitomLogEvents) { var json = JsonSerializer.Serialize(mapitomLogEvents, new JsonSerializerOptions { IgnoreNullValues = false, IgnoreReadOnlyProperties = true }); return(json); }