Skip to content

Commit

Permalink
Fixed: FallbackGroup and json serialization bug(temporary) (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
serdar-eric authored and markmcdowell committed Jun 28, 2016
1 parent c9479ed commit 0769b81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using NLog.Common;
using NLog.Config;
using NLog.Layouts;
using Newtonsoft.Json;
using System.Dynamic;

namespace NLog.Targets.ElasticSearch
{
Expand Down Expand Up @@ -115,6 +117,10 @@ private void SendBatch(IEnumerable<AsyncLogEventInfo> 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)
{
Expand All @@ -138,8 +144,11 @@ private object FormPayload(IEnumerable<LogEventInfo> logEvents)
{"message", Layout.Render(logEvent)}
};

//see : https://github.com/elastic/elasticsearch-net/issues/2052
var ex = JsonConvert.DeserializeObject<ExpandoObject>(JsonConvert.SerializeObject(logEvent.Exception));

if (logEvent.Exception != null)
document.Add("exception", logEvent.Exception);
document.Add("exception", ex);

foreach (var field in Fields)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
Expand Down
1 change: 1 addition & 0 deletions src/NLog.Targets.ElasticSearch/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Elasticsearch.Net" version="2.1.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="NLog" version="4.2.3" targetFramework="net45" />
</packages>

0 comments on commit 0769b81

Please sign in to comment.