Skip to content

Commit

Permalink
Updated Elasticsearch.Net ver. 7.4.2 to fix performance issue
Browse files Browse the repository at this point in the history
  • Loading branch information
snakefoot authored and markmcdowell committed Dec 17, 2019
1 parent 51483d9 commit 8f57b85
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/NLog.Targets.ElasticSearch.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void ExceptionSerializationTest(bool hasExceptionFieldLayout)
var config = new LoggingConfiguration();
config.LoggingRules.Add(rule);

LogManager.ThrowExceptions = true;
LogManager.Configuration = config;

var logger = LogManager.GetLogger("Example");
Expand All @@ -69,6 +70,7 @@ public void SimpleLogTest()
var config = new LoggingConfiguration();
config.LoggingRules.Add(rule);

LogManager.ThrowExceptions = true;
LogManager.Configuration = config;

var logger = LogManager.GetLogger("Example");
Expand All @@ -89,6 +91,7 @@ public void ExceptionTest()
var config = new LoggingConfiguration();
config.LoggingRules.Add(rule);

LogManager.ThrowExceptions = true;
LogManager.Configuration = config;

var logger = LogManager.GetLogger("Example");
Expand All @@ -103,6 +106,7 @@ public void ExceptionTest()
[Fact(Skip = "Integration")]
public void ReadFromConfigTest()
{
LogManager.ThrowExceptions = true;
LogManager.Configuration = new XmlLoggingConfiguration("NLog.Targets.ElasticSearch.Tests.dll.config");

var logger = LogManager.GetLogger("Example");
Expand Down
21 changes: 15 additions & 6 deletions src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using Elasticsearch.Net;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Threading;
using Elasticsearch.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using NLog.Common;
using NLog.Config;
using NLog.Layouts;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Threading;

namespace NLog.Targets.ElasticSearch
{
/// <summary>
/// NLog Target for writing to ElasticSearch using low level client
/// </summary>
[Target("ElasticSearch")]
public class ElasticSearchTarget : TargetWithLayout, IElasticSearchTarget
{
Expand Down Expand Up @@ -143,12 +146,16 @@ public string CloudId
[Obsolete("No longer needed", true)]
public bool ThrowExceptions { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ElasticSearchTarget"/> class.
/// </summary>
public ElasticSearchTarget()
{
Name = "ElasticSearch";
OptimizeBufferReuse = true;
}

/// <inheritdoc />
protected override void InitializeTarget()
{
base.InitializeTarget();
Expand Down Expand Up @@ -201,11 +208,13 @@ protected override void InitializeTarget()
_excludedProperties = new HashSet<string>(ExcludedProperties.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
}

/// <inheritdoc />
protected override void Write(AsyncLogEventInfo logEvent)
{
SendBatch(new[] { logEvent });
}

/// <inheritdoc />
protected override void Write(IList<AsyncLogEventInfo> logEvents)
{
SendBatch(logEvents);
Expand Down
2 changes: 1 addition & 1 deletion src/NLog.Targets.ElasticSearch/ExpandoObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NLog.Targets.ElasticSearch
{
public static class ExpandoObjectExtensions
internal static class ExpandoObjectExtensions
{
/// <summary>
/// Replaces dot ('.') character in Keys with an underscore ('_')
Expand Down
16 changes: 16 additions & 0 deletions src/NLog.Targets.ElasticSearch/Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,33 @@

namespace NLog.Targets.ElasticSearch
{
/// <summary>
/// Additional field details
/// </summary>
[NLogConfigurationItem]
public class Field
{
/// <summary>
/// Name of additional field
/// </summary>
[RequiredParameter]
public string Name { get; set; }

/// <summary>
/// Value with NLog <see cref="NLog.Layouts.Layout"/> rendering support
/// </summary>
[RequiredParameter]
public Layout Layout { get; set; }

/// <summary>
/// Custom type conversion from default string to other type
/// </summary>
/// <remarks>
/// <see cref="System.Object"/> can be used if the <see cref="Layout"/> renders JSON
/// </remarks>
public Type LayoutType { get; set; } = typeof(string);

/// <inheritdoc />
public override string ToString()
{
return $"Name: {Name}, LayoutType: {LayoutType}, Layout: {Layout}";
Expand Down
3 changes: 3 additions & 0 deletions src/NLog.Targets.ElasticSearch/IElasticSearchTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace NLog.Targets.ElasticSearch
{
/// <summary>
/// Interface for NLog Target for writing to ElasticSearch
/// </summary>
public interface IElasticSearchTarget
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<AssemblyOriginatorKeyFile>NLog.Targets.ElasticSearch.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elasticsearch.Net" Version="7.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="NLog" Version="4.6.6" />
<PackageReference Include="Elasticsearch.Net" Version="7.4.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog" Version="4.6.8" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>

</Project>

0 comments on commit 8f57b85

Please sign in to comment.