From 0769b8144746a8cd778b00e8038b80be27a8b09e Mon Sep 17 00:00:00 2001 From: serdar-eric Date: Tue, 28 Jun 2016 23:40:58 +0300 Subject: [PATCH] Fixed: FallbackGroup and json serialization bug(temporary) (#22) --- src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs | 11 ++++++++++- .../NLog.Targets.ElasticSearch.csproj | 4 ++++ src/NLog.Targets.ElasticSearch/packages.config | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs b/src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs index 97408ac..1d24d5b 100644 --- a/src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs +++ b/src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs @@ -5,6 +5,8 @@ using NLog.Common; using NLog.Config; using NLog.Layouts; +using Newtonsoft.Json; +using System.Dynamic; namespace NLog.Targets.ElasticSearch { @@ -115,6 +117,10 @@ private void SendBatch(IEnumerable events) InternalLogger.Error("Failed to send log messages to elasticsearch: status={0}, message=\"{1}\"", result.HttpStatusCode, result.OriginalException?.Message ?? "No error message. Enable Trace logging for more information."); InternalLogger.Trace("Failed to send log messages to elasticsearch: result={0}", result); + + //rethow exception for fallbackgroup setup. + if (result.OriginalException != null) + throw result.OriginalException; } catch (Exception ex) { @@ -138,8 +144,11 @@ private object FormPayload(IEnumerable logEvents) {"message", Layout.Render(logEvent)} }; + //see : https://github.com/elastic/elasticsearch-net/issues/2052 + var ex = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(logEvent.Exception)); + if (logEvent.Exception != null) - document.Add("exception", logEvent.Exception); + document.Add("exception", ex); foreach (var field in Fields) { diff --git a/src/NLog.Targets.ElasticSearch/NLog.Targets.ElasticSearch.csproj b/src/NLog.Targets.ElasticSearch/NLog.Targets.ElasticSearch.csproj index 7a4466e..6d44ec1 100644 --- a/src/NLog.Targets.ElasticSearch/NLog.Targets.ElasticSearch.csproj +++ b/src/NLog.Targets.ElasticSearch/NLog.Targets.ElasticSearch.csproj @@ -38,6 +38,10 @@ True + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + ..\packages\NLog.4.2.3\lib\net45\NLog.dll True diff --git a/src/NLog.Targets.ElasticSearch/packages.config b/src/NLog.Targets.ElasticSearch/packages.config index d706439..6a42cb7 100644 --- a/src/NLog.Targets.ElasticSearch/packages.config +++ b/src/NLog.Targets.ElasticSearch/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file