diff --git a/src/Demo/Demo.csproj b/src/Demo/Demo.csproj index 592a309..7c7b4bd 100644 --- a/src/Demo/Demo.csproj +++ b/src/Demo/Demo.csproj @@ -33,7 +33,7 @@ - ..\packages\NLog.2.1.0\lib\net45\NLog.dll + ..\packages\NLog.4.5.0\lib\net45\NLog.dll diff --git a/src/Demo/packages.config b/src/Demo/packages.config index c3da210..0a3fd1c 100644 --- a/src/Demo/packages.config +++ b/src/Demo/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/NLog.Targets.Fluentd/Fluentd.cs b/src/NLog.Targets.Fluentd/Fluentd.cs index bdb56fc..ea44396 100644 --- a/src/NLog.Targets.Fluentd/Fluentd.cs +++ b/src/NLog.Targets.Fluentd/Fluentd.cs @@ -20,9 +20,9 @@ using System.Text; using System.Net.Sockets; using System.Diagnostics; -using System.Reflection; using MsgPack; using MsgPack.Serialization; +using NLog.Layouts; namespace NLog.Targets { @@ -183,11 +183,11 @@ public FluentdEmitter(Stream stream) [Target("Fluentd")] public class Fluentd : NLog.Targets.TargetWithLayout { - public string Host { get; set; } + public Layout Host { get; set; } public int Port { get; set; } - public string Tag { get; set; } + public Layout Tag { get; set; } public bool NoDelay { get; set; } @@ -246,7 +246,9 @@ protected void EnsureConnected() private void ConnectClient() { - this.client.Connect(this.Host, this.Port); + string hostName = RenderLogEvent(this.Host, LogEventInfo.CreateNullEvent()); + NLog.Common.InternalLogger.Debug("Fluentd Connecting to {0}:{1}", hostName, this.Port); + this.client.Connect(hostName, this.Port); this.stream = this.client.GetStream(); this.emitter = new FluentdEmitter(this.stream); } @@ -309,7 +311,7 @@ protected override void Write(LogEventInfo logEvent) } record.Add("stacktrace", transcodedFrames); } - if (this.IncludeAllProperties && logEvent.Properties.Count > 0) + if (this.IncludeAllProperties && logEvent.HasProperties) { foreach (var property in logEvent.Properties) { @@ -333,7 +335,8 @@ protected override void Write(LogEventInfo logEvent) try { - this.emitter?.Emit(logEvent.TimeStamp, this.Tag, record); + string tagName = RenderLogEvent(this.Tag, logEvent); + this.emitter?.Emit(logEvent.TimeStamp, tagName, record); } catch (Exception ex) { @@ -344,7 +347,7 @@ protected override void Write(LogEventInfo logEvent) private static object SerializePropertyValue(string propertyKey, object propertyValue) { - if (propertyValue == null || Convert.GetTypeCode(propertyValue) != TypeCode.Object || propertyValue is decimal) + if (propertyValue == null || Convert.GetTypeCode(propertyValue) != TypeCode.Object) { return propertyValue; // immutable } @@ -365,7 +368,7 @@ public Fluentd() this.LingerEnabled = true; this.LingerTime = 1000; this.EmitStackTraceWhenAvailable = false; - this.Tag = Assembly.GetCallingAssembly().GetName().Name; + this.Tag = "${processname}"; } } } diff --git a/src/NLog.Targets.Fluentd/NLog.Targets.Fluentd.csproj b/src/NLog.Targets.Fluentd/NLog.Targets.Fluentd.csproj index 1ad2a36..e954b0c 100644 --- a/src/NLog.Targets.Fluentd/NLog.Targets.Fluentd.csproj +++ b/src/NLog.Targets.Fluentd/NLog.Targets.Fluentd.csproj @@ -2,6 +2,7 @@ net35;net40;net45;netstandard2.0 + true NLog Target that emits the log entries to a fluentd node Moriyoshi Koizumi @@ -18,22 +19,14 @@ git://github.com/fluent/NLog.Targets.Fluentd - - true - + + + + - - - - - - - - -