diff --git a/src/NLog.Redis.Tests/RedisTargetTests.cs b/src/NLog.Redis.Tests/RedisTargetTests.cs
index fb3d627..88ee996 100644
--- a/src/NLog.Redis.Tests/RedisTargetTests.cs
+++ b/src/NLog.Redis.Tests/RedisTargetTests.cs
@@ -17,8 +17,7 @@ namespace NLog.Redis.Tests
public class RedisTargetTests
{
protected const string RedisKey = "testkey";
- protected const string RedisHost = "localhost";
- protected const int RedisPort = 6379;
+ protected const string RedisHosts = "localhost:6379";
protected const string RedisPassword = "testingpassword";
protected string Password = null;
@@ -42,8 +41,7 @@ public void NLogRedisConfiguration(string dataType, bool usePassword = false)
// set target properties
redisTarget.Layout = "${uppercase:${level}} ${message}";
- redisTarget.Host = RedisHost;
- redisTarget.Port = RedisPort;
+ redisTarget.Hosts = RedisHosts;
redisTarget.Key = RedisKey;
redisTarget.Db = 0;
redisTarget.DataType = dataType;
@@ -68,7 +66,8 @@ public ConnectionMultiplexer GetRedisConnection(bool usePassword = false)
};
if (usePassword) connectionOptions.Password = RedisPassword;
- connectionOptions.EndPoints.Add(RedisHost, RedisPort);
+ foreach(var host in RedisHosts.Split(','))
+ connectionOptions.EndPoints.Add(host);
return ConnectionMultiplexer.Connect(connectionOptions);
}
diff --git a/src/NLog.Redis/NLog.Redis.nuspec b/src/NLog.Redis/NLog.Redis.nuspec
index b7a82ef..f28f3b2 100644
--- a/src/NLog.Redis/NLog.Redis.nuspec
+++ b/src/NLog.Redis/NLog.Redis.nuspec
@@ -10,7 +10,7 @@
https://github.com/richclement/NLog.Redis
false
$description$
- 1.0.2 - Update dependencies
+ 1.0.3 - Support for master/slave configuration
Copyright 2014
NLog Redis
diff --git a/src/NLog.Redis/Properties/AssemblyInfo.cs b/src/NLog.Redis/Properties/AssemblyInfo.cs
index d0b8dec..60fe0c2 100644
--- a/src/NLog.Redis/Properties/AssemblyInfo.cs
+++ b/src/NLog.Redis/Properties/AssemblyInfo.cs
@@ -35,5 +35,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.2.0")]
-[assembly: AssemblyFileVersion("1.0.2.0")]
+[assembly: AssemblyVersion("1.0.3.1")]
+[assembly: AssemblyFileVersion("1.0.3.1")]
diff --git a/src/NLog.Redis/RedisConnectionManager.cs b/src/NLog.Redis/RedisConnectionManager.cs
index b958ba0..d629998 100644
--- a/src/NLog.Redis/RedisConnectionManager.cs
+++ b/src/NLog.Redis/RedisConnectionManager.cs
@@ -1,5 +1,6 @@
using System;
using StackExchange.Redis;
+using System.Collections.Generic;
namespace NLog.Targets
{
@@ -7,15 +8,24 @@ internal class RedisConnectionManager : IDisposable
{
private ConnectionMultiplexer _connectionMultiplexer;
- private readonly string _host;
- private readonly int _port;
+ private readonly List _hosts;
private readonly int _db;
private readonly string _password;
+ public RedisConnectionManager(List hosts, int db, string password)
+ {
+ _hosts = hosts;
+ _db = db;
+ _password = password;
+
+ InitializeConnection();
+ }
+
+ [Obsolete("Use constructor with hosts instead")]
public RedisConnectionManager(string host, int port, int db, string password)
{
- _host = host;
- _port = port;
+ _hosts = new List();
+ _hosts.Add($"{host}:{port}");
_db = db;
_password = password;
@@ -32,7 +42,10 @@ private void InitializeConnection()
ConnectRetry = 3,
KeepAlive = 5
};
- connectionOptions.EndPoints.Add(_host, _port);
+ foreach (var host in _hosts)
+ {
+ connectionOptions.EndPoints.Add(host);
+ }
if (!string.IsNullOrEmpty(_password))
{
diff --git a/src/NLog.Redis/RedisTarget.cs b/src/NLog.Redis/RedisTarget.cs
index 34978bc..b854c5c 100644
--- a/src/NLog.Redis/RedisTarget.cs
+++ b/src/NLog.Redis/RedisTarget.cs
@@ -1,5 +1,6 @@
using System;
using NLog.Config;
+using System.Linq;
namespace NLog.Targets
{
@@ -12,15 +13,20 @@ public class RedisTarget : TargetWithLayout
///
/// Sets the host name or IP Address of the redis server
///
- [RequiredParameter]
+ [Obsolete("Use hosts instead")]
public string Host { get; set; }
///
/// Sets the port number redis is running on
///
- [RequiredParameter]
+ [Obsolete("Use hosts instead")]
public int Port { get; set; }
+ ///
+ /// Sets the hosts names or IP Addresses and ports of the redis servers
+ ///
+ public string Hosts { get; set; }
+
///
/// Sets the key to be used for either the list or the pub/sub channel in redis
///
@@ -53,7 +59,12 @@ protected override void InitializeTarget()
{
base.InitializeTarget();
- _redisConnectionManager = new RedisConnectionManager(Host, Port, Db, Password);
+ if (!string.IsNullOrWhiteSpace(Host))
+ _redisConnectionManager = new RedisConnectionManager(Host, Port, Db, Password);
+ else if (!string.IsNullOrWhiteSpace(Hosts))
+ _redisConnectionManager = new RedisConnectionManager(Hosts.Split(',').ToList(), Db, Password);
+ else
+ throw new ArgumentException("At least a host must be set");
}
protected override void CloseTarget()
diff --git a/src/NuGetPack.bat b/src/NuGetPack.bat
index 8ba98ba..d238e5a 100644
--- a/src/NuGetPack.bat
+++ b/src/NuGetPack.bat
@@ -1 +1 @@
-.\.nuget\NuGet.exe pack -Symbols .\NLog.Redis\NLog.Redis.csproj
\ No newline at end of file
+.\.nuget\NuGet.exe pack -Symbols .\NLog.Redis\NLog.Redis.csproj -Prop Configuration=Release
\ No newline at end of file