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

Added Layout support for options Host and Tag. Bumped to NLog 4.5 #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Demo/Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog">
<HintPath>..\packages\NLog.2.1.0\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.4.5.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion src/Demo/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="2.1.0" targetFramework="net45" />
<package id="NLog" version="4.5.0" targetFramework="net45" />
</packages>
19 changes: 11 additions & 8 deletions src/NLog.Targets.Fluentd/Fluentd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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
}
Expand All @@ -365,7 +368,7 @@ public Fluentd()
this.LingerEnabled = true;
this.LingerTime = 1000;
this.EmitStackTraceWhenAvailable = false;
this.Tag = Assembly.GetCallingAssembly().GetName().Name;
this.Tag = "${processname}";
}
}
}
17 changes: 5 additions & 12 deletions src/NLog.Targets.Fluentd/NLog.Targets.Fluentd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net35;net40;net45;netstandard2.0</TargetFrameworks>
<DisableImplicitFrameworkReferences Condition=" '$(TargetFramework)' != 'netstandard2.0' ">true</DisableImplicitFrameworkReferences>

<Description>NLog Target that emits the log entries to a fluentd node</Description>
<Authors>Moriyoshi Koizumi</Authors>
Expand All @@ -18,22 +19,14 @@
<RepositoryUrl>git://github.com/fluent/NLog.Targets.Fluentd</RepositoryUrl>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.5.0" />
<PackageReference Include="MsgPack.Cli" Version="0.9.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' ">
<Reference Include="System" />
<Reference Include="System.Core" />

<PackageReference Include="MsgPack.Cli" Version="0.8.0" />
<PackageReference Include="NLog" Version="2.1.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="MsgPack.Cli" Version="0.9.2" />
<PackageReference Include="NLog" Version="4.5.0-rc03" />
</ItemGroup>


</Project>