Skip to content

Commit

Permalink
Deprecating ConnectionStringName
Browse files Browse the repository at this point in the history
  • Loading branch information
markmcdowell committed Jun 12, 2019
1 parent 14dbbd3 commit 9c73c15
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/NLog.Targets.ElasticSearch/ElasticSearchTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class ElasticSearchTarget : TargetWithLayout, IElasticSearchTarget

/// <summary>
/// Gets or sets a connection string name to retrieve the Uri from.
///
///
/// Use as an alternative to Uri
/// </summary>
[Obsolete("Deprecated. Please use the configsetting layout renderer instead.", true)]
public string ConnectionStringName { get; set; }

/// <summary>
Expand Down Expand Up @@ -106,10 +107,10 @@ public class ElasticSearchTarget : TargetWithLayout, IElasticSearchTarget

/// <summary>
/// Gets or sets if exceptions will be rethrown.
///
///
/// Set it to true if ElasticSearchTarget target is used within FallbackGroup target (https://github.com/NLog/NLog/wiki/FallbackGroup-target).
/// </summary>
[Obsolete("No longer needed")]
[Obsolete("No longer needed", true)]
public bool ThrowExceptions { get; set; }

public ElasticSearchTarget()
Expand All @@ -122,7 +123,7 @@ protected override void InitializeTarget()
{
base.InitializeTarget();

var uri = ConnectionStringName.GetConnectionString() ?? (_uri?.Render(LogEventInfo.CreateNullEvent())) ?? string.Empty;
var uri = _uri?.Render(LogEventInfo.CreateNullEvent()) ?? string.Empty;
var nodes = uri.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(url => new Uri(url));
var connectionPool = new StaticConnectionPool(nodes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageReference Include="Elasticsearch.Net" Version="7.0.0-alpha2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="NLog" Version="4.6.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
</ItemGroup>

</Project>
19 changes: 0 additions & 19 deletions src/NLog.Targets.ElasticSearch/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Dynamic;
using System.Globalization;
using Newtonsoft.Json;
using Microsoft.Extensions.Configuration;
using System.IO;

namespace NLog.Targets.ElasticSearch
Expand Down Expand Up @@ -35,23 +34,5 @@ public static object ToSystemType(this string field, Type type, IFormatProvider
return field;
}
}

public static string GetConnectionString(this string name)
{
if (string.IsNullOrEmpty(name))
return null;

var value = Environment.GetEnvironmentVariable(name);
if (!string.IsNullOrEmpty(value))
return value;

var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, reloadOnChange: false); // CreateFileWatcher not supported on all platforms, and not needed

var configuration = builder.Build();

return configuration.GetConnectionString(name);
}
}
}

0 comments on commit 9c73c15

Please sign in to comment.