Skip to content
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
6 changes: 4 additions & 2 deletions src/NLog.RollbarSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>packages\Newtonsoft.Json.5.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=2.0.1.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -48,6 +49,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
55 changes: 31 additions & 24 deletions src/RollbarTarget.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NLog.Common;
using System;
using NLog.Common;
using NLog.Layouts;
using NLog.Targets;
using RollbarSharp;
Expand All @@ -19,28 +20,35 @@ public class RollbarTarget : TargetWithLayout
public Layout Language { get; set; }

public Layout Framework { get; set; }

public Layout Title { get; set; }

public RollbarTarget()
{
Title = "${message}";
}

protected override void Write(LogEventInfo logEvent)
{
var client = CreateClient(logEvent);
var level = ConvertLogLevel(logEvent.Level);
var title = Title.Render(logEvent);
try
{
var client = CreateClient(logEvent);
var level = ConvertLogLevel(logEvent.Level);
var title = Title.Render(logEvent);

var notice = logEvent.Exception != null
? client.NoticeBuilder.CreateExceptionNotice(logEvent.Exception)
: client.NoticeBuilder.CreateMessageNotice(logEvent.FormattedMessage);
var notice = logEvent.Exception != null
? client.NoticeBuilder.CreateExceptionNotice(logEvent.Exception)
: client.NoticeBuilder.CreateMessageNotice(logEvent.FormattedMessage);

notice.Level = level;
notice.Title = title;
notice.Level = level;
notice.Title = title;

client.Send(notice);
client.Send(notice);
}
catch (Exception exception)
{
InternalLogger.Error(exception.ToString());
}
}

/// <summary>
Expand All @@ -51,27 +59,26 @@ protected override void Write(LogEventInfo logEvent)
/// <returns></returns>
private RollbarClient CreateClient(LogEventInfo logEvent)
{
var client = new RollbarClient();
client.RequestStarting += RollbarClientRequestStarting;
client.RequestCompleted += RollbarClientRequestCompleted;

if (!string.IsNullOrEmpty(AccessToken))
client.Configuration.AccessToken = AccessToken;
var configuration = new Configuration(AccessToken);

if (!string.IsNullOrEmpty(Endpoint))
client.Configuration.Endpoint = Endpoint;
configuration.Endpoint = Endpoint;

if (Environment != null)
client.Configuration.Environment = Environment.Render(logEvent);
configuration.Environment = Environment.Render(logEvent);

if (Platform != null)
client.Configuration.Platform = Platform.Render(logEvent);
configuration.Platform = Platform.Render(logEvent);

if (Language != null)
client.Configuration.Language = Language.Render(logEvent);
configuration.Language = Language.Render(logEvent);

if (Framework != null)
client.Configuration.Framework = Framework.Render(logEvent);
configuration.Framework = Framework.Render(logEvent);

var client = new RollbarClient(configuration);
client.RequestStarting += RollbarClientRequestStarting;
client.RequestCompleted += RollbarClientRequestCompleted;

return client;
}
Expand All @@ -83,7 +90,7 @@ private RollbarClient CreateClient(LogEventInfo logEvent)
/// <param name="args"></param>
private static void RollbarClientRequestStarting(object source, RequestStartingEventArgs args)
{
var client = (RollbarClient) source;
var client = (RollbarClient)source;
InternalLogger.Debug("Sending request to {0}: {1}", client.Configuration.Endpoint, args.Payload);
}

Expand Down
11 changes: 11 additions & 0 deletions src/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion src/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="5.0.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net40" />
<package id="NLog" version="2.0.0.2000" targetFramework="net40" />
<package id="RollbarSharp" version="0.2.0.0" targetFramework="net40" />
</packages>