From 59c28f4ff87c618715994ec381b0d3a880e09cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Sierzputowski?= Date: Wed, 16 Sep 2015 17:37:04 +0200 Subject: [PATCH 1/3] Create rollbar client with configuration from NLog --- src/RollbarTarget.cs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/RollbarTarget.cs b/src/RollbarTarget.cs index 84d21b2..99b12f6 100644 --- a/src/RollbarTarget.cs +++ b/src/RollbarTarget.cs @@ -19,14 +19,14 @@ 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); @@ -51,27 +51,26 @@ protected override void Write(LogEventInfo logEvent) /// 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; } @@ -83,7 +82,7 @@ private RollbarClient CreateClient(LogEventInfo logEvent) /// 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); } From d64ca302b50203d45e2b742a0620344167fe9349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Sierzputowski?= Date: Wed, 23 Sep 2015 16:28:49 +0200 Subject: [PATCH 2/3] Add NLog.RollbarSharp exceptions logging to internal logger --- src/RollbarTarget.cs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/RollbarTarget.cs b/src/RollbarTarget.cs index 99b12f6..61617f6 100644 --- a/src/RollbarTarget.cs +++ b/src/RollbarTarget.cs @@ -1,4 +1,5 @@ -using NLog.Common; +using System; +using NLog.Common; using NLog.Layouts; using NLog.Targets; using RollbarSharp; @@ -29,18 +30,25 @@ public RollbarTarget() 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()); + } } /// From 5004e30fd2515c90bb534171d9cd2b862b654e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Sierzputowski?= Date: Thu, 22 Oct 2015 14:18:25 +0200 Subject: [PATCH 3/3] Update Newtonsoft.Json --- src/NLog.RollbarSharp.csproj | 6 ++++-- src/app.config | 11 +++++++++++ src/packages.config | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/app.config diff --git a/src/NLog.RollbarSharp.csproj b/src/NLog.RollbarSharp.csproj index 428b4c7..191fadd 100644 --- a/src/NLog.RollbarSharp.csproj +++ b/src/NLog.RollbarSharp.csproj @@ -30,8 +30,9 @@ 4 - - packages\Newtonsoft.Json.5.0.1\lib\net40\Newtonsoft.Json.dll + + packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll + True False @@ -48,6 +49,7 @@ + diff --git a/src/app.config b/src/app.config new file mode 100644 index 0000000..195db1f --- /dev/null +++ b/src/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/packages.config b/src/packages.config index 744d3c2..a156fdc 100644 --- a/src/packages.config +++ b/src/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file