Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecating ConnectionStringName #97

Merged
merged 1 commit into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}