From b638015be1d40fd2a3295ea27e33be4fe3318410 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 15:32:47 +1300 Subject: [PATCH 01/20] Updated comment. Added target framework net4.7 explicitly. --- Source/Vima.LoggingAbstractor.Core/ILogger.cs | 2 +- .../Vima.LoggingAbstractor.Core.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.Core/ILogger.cs b/Source/Vima.LoggingAbstractor.Core/ILogger.cs index 9fd1f99..b989356 100644 --- a/Source/Vima.LoggingAbstractor.Core/ILogger.cs +++ b/Source/Vima.LoggingAbstractor.Core/ILogger.cs @@ -10,7 +10,7 @@ public interface ILogger /// /// Traces the message. /// - /// The message. + /// The message to be logged. void TraceMessage(string message); /// diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index f091082..67255ba 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -20,7 +20,7 @@ - net46;net45;net40;net35;net20;netstandard1.0;netstandard2.0;portable-net40+sl5+win8+wpa81+wp8;portable-net45+win8+wpa81+wp8 + net47;net46;net45;net40;net35;net20;netstandard1.0;netstandard2.0;portable-net40+sl5+win8+wpa81+wp8;portable-net45+win8+wpa81+wp8 Vima.LoggingAbstractor.Core Vima.LoggingAbstractor.Core From 5fd87de04047edf0e597f26e589ce0ced25ea8b5 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 18:19:35 +1300 Subject: [PATCH 02/20] Added simple implementation of Raygun logger. --- .../RaygunLogger.cs | 63 +++++++++++++++++++ .../RaygunMessageException.cs | 35 +++++++++++ .../Vima.LoggingAbstractor.Raygun.csproj | 20 ++++++ Source/Vima.LoggingAbstractor.sln | 6 ++ 4 files changed, 124 insertions(+) create mode 100644 Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs create mode 100644 Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs new file mode 100644 index 0000000..b48eea6 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -0,0 +1,63 @@ +using System; +using Mindscape.Raygun4Net; +using Vima.LoggingAbstractor.Core; + +namespace Vima.LoggingAbstractor.Raygun +{ + /// + /// Represents an instance of a Raygun logger. + /// + public class RaygunLogger : ILogger + { + private readonly RaygunClient _raygunClient; + + /// + /// Initializes a new instance of the class. + /// + /// The raygun client. + public RaygunLogger(RaygunClient raygunClient) + { + _raygunClient = raygunClient ?? throw new ArgumentNullException(nameof(raygunClient)); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + public void TraceMessage(string message) + { + var messageException = new RaygunMessageException(message); + _raygunClient.Send(messageException); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { + var messageException = new RaygunMessageException(message); + _raygunClient.Send(messageException); + } + + /// + /// Traces the exception. + /// + /// The exception. + public void TraceException(Exception exception) + { + _raygunClient.Send(exception); + } + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { + _raygunClient.Send(exception); + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs new file mode 100644 index 0000000..f0a957a --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs @@ -0,0 +1,35 @@ +using System; + +namespace Vima.LoggingAbstractor.Raygun +{ + /// + /// Represents a wrapper for logging messages to Raygun in the form of exception. + /// + /// + public class RaygunMessageException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public RaygunMessageException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The message that describes the error. + public RaygunMessageException(string message) : base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. + public RaygunMessageException(string message, Exception innerException) : base(message, innerException) + { + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj new file mode 100644 index 0000000..5932d75 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -0,0 +1,20 @@ + + + + net451;netstandard1.6 + + + + + + + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.sln b/Source/Vima.LoggingAbstractor.sln index a2537f2..7f2fcaa 100644 --- a/Source/Vima.LoggingAbstractor.sln +++ b/Source/Vima.LoggingAbstractor.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Core", "Vima.LoggingAbstractor.Core\Vima.LoggingAbstractor.Core.csproj", "{3FB0E95B-327C-4679-8DB4-4769813BED6B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.Raygun", "Vima.LoggingAbstractor.Raygun\Vima.LoggingAbstractor.Raygun.csproj", "{5CADCE35-9157-4644-A9C2-058D8E8AE8BB}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {3FB0E95B-327C-4679-8DB4-4769813BED6B}.Debug|Any CPU.Build.0 = Debug|Any CPU {3FB0E95B-327C-4679-8DB4-4769813BED6B}.Release|Any CPU.ActiveCfg = Release|Any CPU {3FB0E95B-327C-4679-8DB4-4769813BED6B}.Release|Any CPU.Build.0 = Release|Any CPU + {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 0d315b8b6b8354f6fcdfb8e8cf1f09263aea7023 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 18:33:38 +1300 Subject: [PATCH 03/20] Added xml doc output. --- .../Vima.LoggingAbstractor.Core.csproj | 4 +++- .../Vima.LoggingAbstractor.Raygun.csproj | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index 67255ba..2402f7a 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -23,6 +23,9 @@ net47;net46;net45;net40;net35;net20;netstandard1.0;netstandard2.0;portable-net40+sl5+win8+wpa81+wp8;portable-net45+win8+wpa81+wp8 Vima.LoggingAbstractor.Core Vima.LoggingAbstractor.Core + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Core.xml + true + @@ -72,5 +75,4 @@ NETSTANDARD2_0 - diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj index 5932d75..692724f 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -2,6 +2,9 @@ net451;netstandard1.6 + true + + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml From 136f4e583d8032544099150f911b1f02515b1d48 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 20:13:45 +1300 Subject: [PATCH 04/20] Added Sentry client. --- .../SentryLogger.cs | 62 +++++++++++++++++++ .../Vima.LoggingAbstractor.Sentry.csproj | 18 ++++++ Source/Vima.LoggingAbstractor.sln | 8 ++- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs new file mode 100644 index 0000000..be9f969 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -0,0 +1,62 @@ +using System; +using SharpRaven; +using SharpRaven.Data; +using Vima.LoggingAbstractor.Core; + +namespace Vima.LoggingAbstractor.Sentry +{ + /// + /// Represents an instance of a Sentry logger. + /// + public class SentryLogger : ILogger + { + private readonly RavenClient _ravenClient; + + /// + /// Initializes a new instance of the class. + /// + /// The raven client. + public SentryLogger(RavenClient ravenClient) + { + _ravenClient = ravenClient ?? throw new ArgumentNullException(nameof(ravenClient)); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + public void TraceMessage(string message) + { + _ravenClient.Capture(new SentryEvent(message)); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { + _ravenClient.Capture(new SentryEvent(message)); + } + + /// + /// Traces the exception. + /// + /// The exception. + public void TraceException(Exception exception) + { + _ravenClient.Capture(new SentryEvent(exception)); + } + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { + _ravenClient.Capture(new SentryEvent(exception)); + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj new file mode 100644 index 0000000..7083bb1 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -0,0 +1,18 @@ + + + + net47;net46;net45;net40;net35 + true + + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml + + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.sln b/Source/Vima.LoggingAbstractor.sln index 7f2fcaa..6ceac6f 100644 --- a/Source/Vima.LoggingAbstractor.sln +++ b/Source/Vima.LoggingAbstractor.sln @@ -5,7 +5,9 @@ VisualStudioVersion = 15.0.27130.2027 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Core", "Vima.LoggingAbstractor.Core\Vima.LoggingAbstractor.Core.csproj", "{3FB0E95B-327C-4679-8DB4-4769813BED6B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.Raygun", "Vima.LoggingAbstractor.Raygun\Vima.LoggingAbstractor.Raygun.csproj", "{5CADCE35-9157-4644-A9C2-058D8E8AE8BB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Raygun", "Vima.LoggingAbstractor.Raygun\Vima.LoggingAbstractor.Raygun.csproj", "{5CADCE35-9157-4644-A9C2-058D8E8AE8BB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.Sentry", "Vima.LoggingAbstractor.Sentry\Vima.LoggingAbstractor.Sentry.csproj", "{CD2797B3-0861-435A-9B36-ADB457E9242A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +23,10 @@ Global {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Release|Any CPU.ActiveCfg = Release|Any CPU {5CADCE35-9157-4644-A9C2-058D8E8AE8BB}.Release|Any CPU.Build.0 = Release|Any CPU + {CD2797B3-0861-435A-9B36-ADB457E9242A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD2797B3-0861-435A-9B36-ADB457E9242A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD2797B3-0861-435A-9B36-ADB457E9242A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD2797B3-0861-435A-9B36-ADB457E9242A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 2ff547871f463bf137d8ca9b6b79e7671d1d7a4f Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 20:35:25 +1300 Subject: [PATCH 05/20] Added AppInsights logger. --- .../AppInsightsLogger.cs | 63 +++++++++++++++++++ .../Vima.LoggingAbstractor.AppInsights.csproj | 18 ++++++ Source/Vima.LoggingAbstractor.sln | 6 ++ 3 files changed, 87 insertions(+) create mode 100644 Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs new file mode 100644 index 0000000..c31f4bb --- /dev/null +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -0,0 +1,63 @@ +using System; +using Microsoft.ApplicationInsights; +using Microsoft.ApplicationInsights.DataContracts; +using Vima.LoggingAbstractor.Core; + +namespace Vima.LoggingAbstractor.AppInsights +{ + /// + /// Represents an instance of an Application Insights logger. + /// + public class AppInsightsLogger : ILogger + { + private readonly TelemetryClient _telemetryClient; + + /// + /// Initializes a new instance of the class. + /// + /// The Application Insights client. + public AppInsightsLogger(TelemetryClient telemetryClient) + { + _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + public void TraceMessage(string message) + { + _telemetryClient.Track(new TraceTelemetry(message)); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { + _telemetryClient.Track(new TraceTelemetry(message)); + } + + /// + /// Traces the exception. + /// + /// The exception. + public void TraceException(Exception exception) + { + _telemetryClient.Track(new ExceptionTelemetry(exception)); + + } + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { + _telemetryClient.Track(new ExceptionTelemetry(exception)); + } + } +} diff --git a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj new file mode 100644 index 0000000..c4e8d2c --- /dev/null +++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj @@ -0,0 +1,18 @@ + + + + net47;net46;net45;net40;netstandard1.3;netstandard2.0 + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.AppInsights.xml + true + + + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.sln b/Source/Vima.LoggingAbstractor.sln index 6ceac6f..07141c5 100644 --- a/Source/Vima.LoggingAbstractor.sln +++ b/Source/Vima.LoggingAbstractor.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Rayg EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.Sentry", "Vima.LoggingAbstractor.Sentry\Vima.LoggingAbstractor.Sentry.csproj", "{CD2797B3-0861-435A-9B36-ADB457E9242A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.AppInsights", "Vima.LoggingAbstractor.AppInsights\Vima.LoggingAbstractor.AppInsights.csproj", "{5F507DDE-69FC-464F-AC7E-069E2D16D05D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {CD2797B3-0861-435A-9B36-ADB457E9242A}.Debug|Any CPU.Build.0 = Debug|Any CPU {CD2797B3-0861-435A-9B36-ADB457E9242A}.Release|Any CPU.ActiveCfg = Release|Any CPU {CD2797B3-0861-435A-9B36-ADB457E9242A}.Release|Any CPU.Build.0 = Release|Any CPU + {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 7aad384bd0205dadc83b2183eb9f809075abb412 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 20:59:21 +1300 Subject: [PATCH 06/20] Updated csproj files and script to generate nuget packages. --- Scripts/Build.ps1 | 5 +++- .../Vima.LoggingAbstractor.AppInsights.csproj | 21 +++++++++++++++++ .../Vima.LoggingAbstractor.Raygun.csproj | 23 ++++++++++++++++++- .../Vima.LoggingAbstractor.Sentry.csproj | 23 ++++++++++++++++++- 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Scripts/Build.ps1 b/Scripts/Build.ps1 index fcc0fc1..20e24f0 100644 --- a/Scripts/Build.ps1 +++ b/Scripts/Build.ps1 @@ -29,7 +29,10 @@ properties { ) $ProjectsToPublish=@( - "$SourceDirectory\Vima.LoggingAbstractor.Core\Vima.LoggingAbstractor.Core.csproj" + "$SourceDirectory\Vima.LoggingAbstractor.Core\Vima.LoggingAbstractor.Core.csproj", + "$SourceDirectory\Vima.LoggingAbstractor.AppInsights\Vima.LoggingAbstractor.AppInsights.csproj", + "$SourceDirectory\Vima.LoggingAbstractor.Raygun\Vima.LoggingAbstractor.Raygun.csproj", + "$SourceDirectory\Vima.LoggingAbstractor.Sentry\Vima.LoggingAbstractor.Sentry.csproj" ) } diff --git a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj index c4e8d2c..f45964a 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj @@ -1,7 +1,28 @@ + + 1.0.0 + 1.0.0 + Victor Usoltsev + Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. + Copyright © Victor Usoltsev 2018 + https://github.com/bernarden/LoggingAbstractor/blob/master/LICENSE + https://raw.githubusercontent.com/bernarden/LoggingAbstractor/master/Resources/NugetIcon.png + https://github.com/bernarden/LoggingAbstractor + git + logging abstractor abstraction logger + https://github.com/bernarden/LoggingAbstractor + Vima + en-US + False + LoggingAbstractor.AppInsights + LoggingAbstractor.AppInsights + + net47;net46;net45;net40;netstandard1.3;netstandard2.0 + Vima.LoggingAbstractor.AppInsights + Vima.LoggingAbstractor.AppInsights bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.AppInsights.xml true diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj index 692724f..76c4619 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -1,10 +1,31 @@ + + 1.0.0 + 1.0.0 + Victor Usoltsev + Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. + Copyright © Victor Usoltsev 2018 + https://github.com/bernarden/LoggingAbstractor/blob/master/LICENSE + https://raw.githubusercontent.com/bernarden/LoggingAbstractor/master/Resources/NugetIcon.png + https://github.com/bernarden/LoggingAbstractor + git + logging abstractor abstraction logger + https://github.com/bernarden/LoggingAbstractor + Vima + en-US + False + LoggingAbstractor.Raygun + LoggingAbstractor.Raygun + + net451;netstandard1.6 + Vima.LoggingAbstractor.Raygun + Vima.LoggingAbstractor.Raygun + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml true - bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj index 7083bb1..4538a2b 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -1,10 +1,31 @@ + + 1.0.0 + 1.0.0 + Victor Usoltsev + Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. + Copyright © Victor Usoltsev 2018 + https://github.com/bernarden/LoggingAbstractor/blob/master/LICENSE + https://raw.githubusercontent.com/bernarden/LoggingAbstractor/master/Resources/NugetIcon.png + https://github.com/bernarden/LoggingAbstractor + git + logging abstractor abstraction logger + https://github.com/bernarden/LoggingAbstractor + Vima + en-US + False + LoggingAbstractor.Sentry + LoggingAbstractor.Sentry + + net47;net46;net45;net40;net35 + Vima.LoggingAbstractor.Sentry + Vima.LoggingAbstractor.Sentry + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml true - bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml From 8f25df7de18ce5ec1a8b7d7d50a7828694809061 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 23:28:46 +1300 Subject: [PATCH 07/20] Added code analysis. --- .../AppInsightsLogger.cs | 3 +- .../Vima.LoggingAbstractor.AppInsights.csproj | 2 + Source/Vima.LoggingAbstractor.Core/ILogger.cs | 2 +- .../Vima.LoggingAbstractor.Core.csproj | 5 ++ .../RaygunLogger.cs | 2 +- .../RaygunMessageException.cs | 6 +- .../Vima.LoggingAbstractor.Raygun.csproj | 6 ++ .../SentryLogger.cs | 2 +- .../Vima.LoggingAbstractor.Sentry.csproj | 3 + Source/ca.ruleset | 82 +++++++++++++++++++ 10 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 Source/ca.ruleset diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index c31f4bb..1180790 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -6,7 +6,7 @@ namespace Vima.LoggingAbstractor.AppInsights { /// - /// Represents an instance of an Application Insights logger. + /// Represents an instance of an Application Insights logger. /// public class AppInsightsLogger : ILogger { @@ -47,7 +47,6 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev public void TraceException(Exception exception) { _telemetryClient.Track(new ExceptionTelemetry(exception)); - } /// diff --git a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj index f45964a..9ff19da 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj @@ -24,12 +24,14 @@ Vima.LoggingAbstractor.AppInsights Vima.LoggingAbstractor.AppInsights bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.AppInsights.xml + ..\ca.ruleset true + diff --git a/Source/Vima.LoggingAbstractor.Core/ILogger.cs b/Source/Vima.LoggingAbstractor.Core/ILogger.cs index b989356..301c2e8 100644 --- a/Source/Vima.LoggingAbstractor.Core/ILogger.cs +++ b/Source/Vima.LoggingAbstractor.Core/ILogger.cs @@ -3,7 +3,7 @@ namespace Vima.LoggingAbstractor.Core { /// - /// Represents an instance of a logger. + /// Represents an instance of a logger. /// public interface ILogger { diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index 2402f7a..4b8c092 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -24,6 +24,7 @@ Vima.LoggingAbstractor.Core Vima.LoggingAbstractor.Core bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Core.xml + ..\ca.ruleset true @@ -75,4 +76,8 @@ NETSTANDARD2_0 + + + + diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index b48eea6..34dc290 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -5,7 +5,7 @@ namespace Vima.LoggingAbstractor.Raygun { /// - /// Represents an instance of a Raygun logger. + /// Represents an instance of a Raygun logger. /// public class RaygunLogger : ILogger { diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs index f0a957a..6824633 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunMessageException.cs @@ -19,7 +19,8 @@ public RaygunMessageException() /// Initializes a new instance of the class. /// /// The message that describes the error. - public RaygunMessageException(string message) : base(message) + public RaygunMessageException(string message) + : base(message) { } @@ -28,7 +29,8 @@ public RaygunMessageException(string message) : base(message) /// /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. - public RaygunMessageException(string message, Exception innerException) : base(message, innerException) + public RaygunMessageException(string message, Exception innerException) + : base(message, innerException) { } } diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj index 76c4619..abf4051 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -24,6 +24,7 @@ Vima.LoggingAbstractor.Raygun Vima.LoggingAbstractor.Raygun bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml + ..\ca.ruleset true @@ -37,6 +38,11 @@ + + + + + diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index be9f969..4f4f0c7 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -6,7 +6,7 @@ namespace Vima.LoggingAbstractor.Sentry { /// - /// Represents an instance of a Sentry logger. + /// Represents an instance of a Sentry logger. /// public class SentryLogger : ILogger { diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj index 4538a2b..324b9ae 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -24,12 +24,15 @@ Vima.LoggingAbstractor.Sentry Vima.LoggingAbstractor.Sentry bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml + ..\ca.ruleset true + + diff --git a/Source/ca.ruleset b/Source/ca.ruleset new file mode 100644 index 0000000..92ca674 --- /dev/null +++ b/Source/ca.ruleset @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 7ee352a0717f1d772458abaa4f2c103c328cfe85 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 6 Feb 2018 23:53:51 +1300 Subject: [PATCH 08/20] Removed code analysis as a dependency on nuspec. --- .../Vima.LoggingAbstractor.AppInsights.csproj | 2 +- .../Vima.LoggingAbstractor.Core.csproj | 2 +- .../Vima.LoggingAbstractor.Raygun.csproj | 3 +-- .../Vima.LoggingAbstractor.Sentry.csproj | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj index 9ff19da..232efb1 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj @@ -31,7 +31,7 @@ - + diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index 4b8c092..acd14f5 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -78,6 +78,6 @@ - + diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj index abf4051..894f369 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -39,8 +39,7 @@ - - + diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj index 324b9ae..d1777c4 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -30,9 +30,8 @@ - - + From d28e5617628daf6d9ca0269f62e88cfbd6919111 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Sun, 11 Feb 2018 22:47:56 +1300 Subject: [PATCH 09/20] Updates logging interface to include additional parameters. --- .../AppInsightsLogger.cs | 29 +++++++++++++-- Source/Vima.LoggingAbstractor.Core/ILogger.cs | 18 ++++++++++ .../Parameters/ILoggingAdditionalParameter.cs | 9 +++++ .../Parameters/LoggingParameterType.cs | 13 +++++++ .../Parameters/LoggingTagsParameter.cs | 36 +++++++++++++++++++ .../RaygunLogger.cs | 29 +++++++++++++-- .../SentryLogger.cs | 28 +++++++++++++-- 7 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs create mode 100644 Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs create mode 100644 Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index 1180790..55ecb0b 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -1,7 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; using Vima.LoggingAbstractor.Core; +using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.AppInsights { @@ -27,7 +30,7 @@ public AppInsightsLogger(TelemetryClient telemetryClient) /// The message to be logged. public void TraceMessage(string message) { - _telemetryClient.Track(new TraceTelemetry(message)); + TraceMessage(message, LoggingSeverityLevel.Verbose); } /// @@ -36,6 +39,17 @@ public void TraceMessage(string message) /// The message to be logged. /// The logging severity level. public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { + TraceMessage(message, loggingSeverityLevel, Enumerable.Empty()); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + /// The additional parameters. + public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _telemetryClient.Track(new TraceTelemetry(message)); } @@ -46,7 +60,7 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev /// The exception. public void TraceException(Exception exception) { - _telemetryClient.Track(new ExceptionTelemetry(exception)); + TraceException(exception, LoggingSeverityLevel.Critical); } /// @@ -55,6 +69,17 @@ public void TraceException(Exception exception) /// The exception. /// The logging severity level. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { + TraceException(exception, loggingSeverityLevel, Enumerable.Empty()); + } + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + /// The additional parameters. + public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _telemetryClient.Track(new ExceptionTelemetry(exception)); } diff --git a/Source/Vima.LoggingAbstractor.Core/ILogger.cs b/Source/Vima.LoggingAbstractor.Core/ILogger.cs index 301c2e8..11c671a 100644 --- a/Source/Vima.LoggingAbstractor.Core/ILogger.cs +++ b/Source/Vima.LoggingAbstractor.Core/ILogger.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Core { @@ -20,6 +22,14 @@ public interface ILogger /// The logging severity level. void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel); + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + /// The additional parameters. + void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + /// /// Traces the exception. /// @@ -32,5 +42,13 @@ public interface ILogger /// The exception. /// The logging severity level. void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel); + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + /// The additional parameters. + void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); } } diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs new file mode 100644 index 0000000..811785b --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs @@ -0,0 +1,9 @@ +namespace Vima.LoggingAbstractor.Core.Parameters +{ + /// + /// Represents additional logging parameter. + /// + public interface ILoggingAdditionalParameter + { + } +} diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs new file mode 100644 index 0000000..82c732b --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs @@ -0,0 +1,13 @@ +namespace Vima.LoggingAbstractor.Core.Parameters +{ + /// + /// Represents logging parameter type. + /// + public enum LoggingParameterType + { + /// + /// The tags parameter. + /// + Tags + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs new file mode 100644 index 0000000..8d86ed4 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; + +namespace Vima.LoggingAbstractor.Core.Parameters +{ + /// + /// Represents logging tags parameter. + /// + public class LoggingTagsParameter : ILoggingAdditionalParameter + { + /// + /// Initializes a new instance of the class. + /// + /// The tags. + public LoggingTagsParameter(IEnumerable tags) + { + Tags = tags ?? throw new ArgumentNullException(nameof(tags)); + } + + /// + /// Gets the tags. + /// + /// + /// The tags. + /// + public IEnumerable Tags { get; } + + /// + /// Gets the type of the logging parameter type. + /// + /// + /// The type of the logging parameter type. + /// + internal LoggingParameterType LoggingParameterType => LoggingParameterType.Tags; + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index 34dc290..9567d3c 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using Mindscape.Raygun4Net; using Vima.LoggingAbstractor.Core; +using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Raygun { @@ -26,8 +28,7 @@ public RaygunLogger(RaygunClient raygunClient) /// The message to be logged. public void TraceMessage(string message) { - var messageException = new RaygunMessageException(message); - _raygunClient.Send(messageException); + TraceMessage(message, LoggingSeverityLevel.Verbose); } /// @@ -36,6 +37,17 @@ public void TraceMessage(string message) /// The message to be logged. /// The logging severity level. public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { + TraceMessage(message, LoggingSeverityLevel.Verbose, new List()); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + /// The additional parameters. + public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { var messageException = new RaygunMessageException(message); _raygunClient.Send(messageException); @@ -47,7 +59,7 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev /// The exception. public void TraceException(Exception exception) { - _raygunClient.Send(exception); + TraceException(exception, LoggingSeverityLevel.Critical); } /// @@ -56,6 +68,17 @@ public void TraceException(Exception exception) /// The exception. /// The logging severity level. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { + TraceException(exception, LoggingSeverityLevel.Critical, new List()); + } + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + /// The additional parameters. + public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _raygunClient.Send(exception); } diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index 4f4f0c7..b134d69 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using SharpRaven; using SharpRaven.Data; using Vima.LoggingAbstractor.Core; +using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Sentry { @@ -27,7 +29,7 @@ public SentryLogger(RavenClient ravenClient) /// The message to be logged. public void TraceMessage(string message) { - _ravenClient.Capture(new SentryEvent(message)); + TraceMessage(message, LoggingSeverityLevel.Verbose); } /// @@ -36,6 +38,17 @@ public void TraceMessage(string message) /// The message to be logged. /// The logging severity level. public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { + TraceMessage(message, LoggingSeverityLevel.Verbose, new List()); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + /// The additional parameters. + public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _ravenClient.Capture(new SentryEvent(message)); } @@ -46,7 +59,7 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev /// The exception. public void TraceException(Exception exception) { - _ravenClient.Capture(new SentryEvent(exception)); + TraceException(exception, LoggingSeverityLevel.Critical); } /// @@ -55,6 +68,17 @@ public void TraceException(Exception exception) /// The exception. /// The logging severity level. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { + TraceException(exception, LoggingSeverityLevel.Critical, new List()); + } + + /// + /// Traces the exception. + /// + /// The exception. + /// The logging severity level. + /// The additional parameters. + public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _ravenClient.Capture(new SentryEvent(exception)); } From de99a9b6c3b8aed9bfe3679626a16b57e4fba561 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Sat, 17 Feb 2018 18:54:09 +1300 Subject: [PATCH 10/20] Updates comments. --- .../Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs | 6 +++--- Source/Vima.LoggingAbstractor.Core/ILogger.cs | 6 +++--- Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs | 6 +++--- Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index 55ecb0b..2b36f2d 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -57,7 +57,7 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. public void TraceException(Exception exception) { TraceException(exception, LoggingSeverityLevel.Critical); @@ -66,7 +66,7 @@ public void TraceException(Exception exception) /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) { @@ -76,7 +76,7 @@ public void TraceException(Exception exception, LoggingSeverityLevel loggingSeve /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. /// The additional parameters. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) diff --git a/Source/Vima.LoggingAbstractor.Core/ILogger.cs b/Source/Vima.LoggingAbstractor.Core/ILogger.cs index 11c671a..6dac132 100644 --- a/Source/Vima.LoggingAbstractor.Core/ILogger.cs +++ b/Source/Vima.LoggingAbstractor.Core/ILogger.cs @@ -33,20 +33,20 @@ public interface ILogger /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. void TraceException(Exception exception); /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel); /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. /// The additional parameters. void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index 9567d3c..f32265c 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -56,7 +56,7 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. public void TraceException(Exception exception) { TraceException(exception, LoggingSeverityLevel.Critical); @@ -65,7 +65,7 @@ public void TraceException(Exception exception) /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) { @@ -75,7 +75,7 @@ public void TraceException(Exception exception, LoggingSeverityLevel loggingSeve /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. /// The additional parameters. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index b134d69..b8c8692 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -56,7 +56,7 @@ public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLev /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. public void TraceException(Exception exception) { TraceException(exception, LoggingSeverityLevel.Critical); @@ -65,7 +65,7 @@ public void TraceException(Exception exception) /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) { @@ -75,7 +75,7 @@ public void TraceException(Exception exception, LoggingSeverityLevel loggingSeve /// /// Traces the exception. /// - /// The exception. + /// The exception to be logged. /// The logging severity level. /// The additional parameters. public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) From 76c146caded2f4690f5ed6bc4f81fa8024030895 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Sat, 17 Feb 2018 19:12:13 +1300 Subject: [PATCH 11/20] Adds abstract logger base to reduce code repetitions. --- .../AppInsightsLogger.cs | 45 +---------- .../Vima.LoggingAbstractor.Core/LoggerBase.cs | 77 +++++++++++++++++++ .../RaygunLogger.cs | 44 +---------- .../SentryLogger.cs | 44 +---------- 4 files changed, 86 insertions(+), 124 deletions(-) create mode 100644 Source/Vima.LoggingAbstractor.Core/LoggerBase.cs diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index 2b36f2d..ee6a20e 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; using Vima.LoggingAbstractor.Core; @@ -11,7 +10,7 @@ namespace Vima.LoggingAbstractor.AppInsights /// /// Represents an instance of an Application Insights logger. /// - public class AppInsightsLogger : ILogger + public class AppInsightsLogger : LoggerBase { private readonly TelemetryClient _telemetryClient; @@ -24,62 +23,24 @@ public AppInsightsLogger(TelemetryClient telemetryClient) _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); } - /// - /// Traces the message. - /// - /// The message to be logged. - public void TraceMessage(string message) - { - TraceMessage(message, LoggingSeverityLevel.Verbose); - } - - /// - /// Traces the message. - /// - /// The message to be logged. - /// The logging severity level. - public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) - { - TraceMessage(message, loggingSeverityLevel, Enumerable.Empty()); - } - /// /// Traces the message. /// /// The message to be logged. /// The logging severity level. /// The additional parameters. - public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _telemetryClient.Track(new TraceTelemetry(message)); } - /// - /// Traces the exception. - /// - /// The exception to be logged. - public void TraceException(Exception exception) - { - TraceException(exception, LoggingSeverityLevel.Critical); - } - - /// - /// Traces the exception. - /// - /// The exception to be logged. - /// The logging severity level. - public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) - { - TraceException(exception, loggingSeverityLevel, Enumerable.Empty()); - } - /// /// Traces the exception. /// /// The exception to be logged. /// The logging severity level. /// The additional parameters. - public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _telemetryClient.Track(new ExceptionTelemetry(exception)); } diff --git a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs new file mode 100644 index 0000000..29fc22e --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +#if !NET20 +using System.Linq; +#endif +using Vima.LoggingAbstractor.Core.Parameters; + +namespace Vima.LoggingAbstractor.Core +{ + /// + /// Represents an instance of a logger. + /// + public abstract class LoggerBase : ILogger + { + /// + /// Traces the message. + /// + /// The message to be logged. + public virtual void TraceMessage(string message) + { + TraceMessage(message, LoggingSeverityLevel.Verbose); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + public virtual void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + { +#if NET20 + TraceMessage(message, loggingSeverityLevel, new List()); +#else + TraceMessage(message, loggingSeverityLevel, Enumerable.Empty()); +#endif + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging severity level. + /// The additional parameters. + public abstract void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + + /// + /// Traces the exception. + /// + /// The exception to be logged. + public virtual void TraceException(Exception exception) + { + TraceException(exception, LoggingSeverityLevel.Critical); + } + + /// + /// Traces the exception. + /// + /// The exception to be logged. + /// The logging severity level. + public virtual void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + { +#if NET20 + TraceException(exception, loggingSeverityLevel, new List()); +#else + TraceException(exception, loggingSeverityLevel, Enumerable.Empty()); +#endif + } + + /// + /// Traces the exception. + /// + /// The exception to be logged. + /// The logging severity level. + /// The additional parameters. + public abstract void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index f32265c..947261b 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -9,7 +9,7 @@ namespace Vima.LoggingAbstractor.Raygun /// /// Represents an instance of a Raygun logger. /// - public class RaygunLogger : ILogger + public class RaygunLogger : LoggerBase { private readonly RaygunClient _raygunClient; @@ -22,63 +22,25 @@ public RaygunLogger(RaygunClient raygunClient) _raygunClient = raygunClient ?? throw new ArgumentNullException(nameof(raygunClient)); } - /// - /// Traces the message. - /// - /// The message to be logged. - public void TraceMessage(string message) - { - TraceMessage(message, LoggingSeverityLevel.Verbose); - } - - /// - /// Traces the message. - /// - /// The message to be logged. - /// The logging severity level. - public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) - { - TraceMessage(message, LoggingSeverityLevel.Verbose, new List()); - } - /// /// Traces the message. /// /// The message to be logged. /// The logging severity level. /// The additional parameters. - public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { var messageException = new RaygunMessageException(message); _raygunClient.Send(messageException); } - /// - /// Traces the exception. - /// - /// The exception to be logged. - public void TraceException(Exception exception) - { - TraceException(exception, LoggingSeverityLevel.Critical); - } - - /// - /// Traces the exception. - /// - /// The exception to be logged. - /// The logging severity level. - public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) - { - TraceException(exception, LoggingSeverityLevel.Critical, new List()); - } - /// /// Traces the exception. /// /// The exception to be logged. /// The logging severity level. /// The additional parameters. - public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _raygunClient.Send(exception); } diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index b8c8692..8a8d042 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -10,7 +10,7 @@ namespace Vima.LoggingAbstractor.Sentry /// /// Represents an instance of a Sentry logger. /// - public class SentryLogger : ILogger + public class SentryLogger : LoggerBase { private readonly RavenClient _ravenClient; @@ -23,62 +23,24 @@ public SentryLogger(RavenClient ravenClient) _ravenClient = ravenClient ?? throw new ArgumentNullException(nameof(ravenClient)); } - /// - /// Traces the message. - /// - /// The message to be logged. - public void TraceMessage(string message) - { - TraceMessage(message, LoggingSeverityLevel.Verbose); - } - - /// - /// Traces the message. - /// - /// The message to be logged. - /// The logging severity level. - public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) - { - TraceMessage(message, LoggingSeverityLevel.Verbose, new List()); - } - /// /// Traces the message. /// /// The message to be logged. /// The logging severity level. /// The additional parameters. - public void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _ravenClient.Capture(new SentryEvent(message)); } - /// - /// Traces the exception. - /// - /// The exception to be logged. - public void TraceException(Exception exception) - { - TraceException(exception, LoggingSeverityLevel.Critical); - } - - /// - /// Traces the exception. - /// - /// The exception to be logged. - /// The logging severity level. - public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) - { - TraceException(exception, LoggingSeverityLevel.Critical, new List()); - } - /// /// Traces the exception. /// /// The exception to be logged. /// The logging severity level. /// The additional parameters. - public void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { _ravenClient.Capture(new SentryEvent(exception)); } From 01f143ef37841be7ecef7341ab9c63d19f40de6c Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Sat, 17 Feb 2018 19:30:38 +1300 Subject: [PATCH 12/20] Updates solution structure. --- Source/Vima.LoggingAbstractor.sln | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.sln b/Source/Vima.LoggingAbstractor.sln index 07141c5..d4ff5d3 100644 --- a/Source/Vima.LoggingAbstractor.sln +++ b/Source/Vima.LoggingAbstractor.sln @@ -7,9 +7,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Core EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Raygun", "Vima.LoggingAbstractor.Raygun\Vima.LoggingAbstractor.Raygun.csproj", "{5CADCE35-9157-4644-A9C2-058D8E8AE8BB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.Sentry", "Vima.LoggingAbstractor.Sentry\Vima.LoggingAbstractor.Sentry.csproj", "{CD2797B3-0861-435A-9B36-ADB457E9242A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Sentry", "Vima.LoggingAbstractor.Sentry\Vima.LoggingAbstractor.Sentry.csproj", "{CD2797B3-0861-435A-9B36-ADB457E9242A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vima.LoggingAbstractor.AppInsights", "Vima.LoggingAbstractor.AppInsights\Vima.LoggingAbstractor.AppInsights.csproj", "{5F507DDE-69FC-464F-AC7E-069E2D16D05D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.AppInsights", "Vima.LoggingAbstractor.AppInsights\Vima.LoggingAbstractor.AppInsights.csproj", "{5F507DDE-69FC-464F-AC7E-069E2D16D05D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{3C17934E-6CA1-4F9B-BBB5-40405D4489E2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Clients", "Clients", "{9F33D991-BD90-406B-9A62-4D1C7D184368}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{ECC3568E-2B5D-4CD9-90E3-8727BA55E179}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,6 +43,12 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {3FB0E95B-327C-4679-8DB4-4769813BED6B} = {3C17934E-6CA1-4F9B-BBB5-40405D4489E2} + {5CADCE35-9157-4644-A9C2-058D8E8AE8BB} = {9F33D991-BD90-406B-9A62-4D1C7D184368} + {CD2797B3-0861-435A-9B36-ADB457E9242A} = {9F33D991-BD90-406B-9A62-4D1C7D184368} + {5F507DDE-69FC-464F-AC7E-069E2D16D05D} = {9F33D991-BD90-406B-9A62-4D1C7D184368} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {81C432BA-8657-42A6-BC44-C0D267D70BF8} EndGlobalSection From 4e8d935ade40dc362f0961a32144460505ed3d47 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Sun, 18 Feb 2018 16:02:10 +1300 Subject: [PATCH 13/20] Adds minimal logging level check. --- .../AppInsightsLogger.cs | 12 ++++++++++++ Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs | 12 ++++++++++++ Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index ee6a20e..203da9e 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -23,6 +23,8 @@ public AppInsightsLogger(TelemetryClient telemetryClient) _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); } + private static LoggingSeverityLevel MinimalLoggingLevel => LoggingSeverityLevel.Verbose; + /// /// Traces the message. /// @@ -31,6 +33,11 @@ public AppInsightsLogger(TelemetryClient telemetryClient) /// The additional parameters. public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { + if (loggingSeverityLevel < MinimalLoggingLevel) + { + return; + } + _telemetryClient.Track(new TraceTelemetry(message)); } @@ -42,6 +49,11 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// The additional parameters. public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { + if (loggingSeverityLevel < MinimalLoggingLevel) + { + return; + } + _telemetryClient.Track(new ExceptionTelemetry(exception)); } } diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index 947261b..fa43a44 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -22,6 +22,8 @@ public RaygunLogger(RaygunClient raygunClient) _raygunClient = raygunClient ?? throw new ArgumentNullException(nameof(raygunClient)); } + private static LoggingSeverityLevel MinimalLoggingLevel => LoggingSeverityLevel.Verbose; + /// /// Traces the message. /// @@ -30,6 +32,11 @@ public RaygunLogger(RaygunClient raygunClient) /// The additional parameters. public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { + if (loggingSeverityLevel < MinimalLoggingLevel) + { + return; + } + var messageException = new RaygunMessageException(message); _raygunClient.Send(messageException); } @@ -42,6 +49,11 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// The additional parameters. public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { + if (loggingSeverityLevel < MinimalLoggingLevel) + { + return; + } + _raygunClient.Send(exception); } } diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index 8a8d042..6f29efb 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -23,6 +23,8 @@ public SentryLogger(RavenClient ravenClient) _ravenClient = ravenClient ?? throw new ArgumentNullException(nameof(ravenClient)); } + private static LoggingSeverityLevel MinimalLoggingLevel => LoggingSeverityLevel.Verbose; + /// /// Traces the message. /// @@ -31,6 +33,11 @@ public SentryLogger(RavenClient ravenClient) /// The additional parameters. public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { + if (loggingSeverityLevel < MinimalLoggingLevel) + { + return; + } + _ravenClient.Capture(new SentryEvent(message)); } @@ -42,6 +49,11 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// The additional parameters. public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { + if (loggingSeverityLevel < MinimalLoggingLevel) + { + return; + } + _ravenClient.Capture(new SentryEvent(exception)); } } From c6cfa805378bb600d4a4f413ff9c542875b7aded Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Sun, 18 Feb 2018 16:06:35 +1300 Subject: [PATCH 14/20] Adds test projects for core and clients projects. --- Scripts/Build.ps1 | 3 +- .../UnitTest1.cs | 12 + ...LoggingAbstractor.AppInsights.Tests.csproj | 21 + .../UnitTest1.cs | 12 + .../Vima.LoggingAbstractor.Core.Tests.csproj | 21 + .../Vima.LoggingAbstractor.Core.csproj | 40 +- .../UnitTest1.cs | 12 + ...Vima.LoggingAbstractor.Raygun.Tests.csproj | 21 + .../UnitTest1.cs | 12 + ...Vima.LoggingAbstractor.Sentry.Tests.csproj | 21 + .../Vima.LoggingAbstractor.Sentry.csproj | 2 +- Source/Vima.LoggingAbstractor.sln | 28 + Source/ca-tests.ruleset | 666 ++++++++++++++++++ 13 files changed, 837 insertions(+), 34 deletions(-) create mode 100644 Source/Vima.LoggingAbstractor.AppInsights.Tests/UnitTest1.cs create mode 100644 Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj create mode 100644 Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs create mode 100644 Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj create mode 100644 Source/Vima.LoggingAbstractor.Raygun.Tests/UnitTest1.cs create mode 100644 Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj create mode 100644 Source/Vima.LoggingAbstractor.Sentry.Tests/UnitTest1.cs create mode 100644 Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj create mode 100644 Source/ca-tests.ruleset diff --git a/Scripts/Build.ps1 b/Scripts/Build.ps1 index 20e24f0..5afe620 100644 --- a/Scripts/Build.ps1 +++ b/Scripts/Build.ps1 @@ -25,7 +25,8 @@ properties { @{"Framework" = "net45"; "TestingFramework" = "net-4.5"; "Utility" = "NUnit";}, @{"Framework" = "net451"; "TestingFramework" = "net-4.0"; "Utility" = "NUnit";}, @{"Framework" = "net452"; "TestingFramework" = "net-4.5"; "Utility" = "NUnit";}, - @{"Framework" = "net46"; "TestingFramework" = "net46"; "Utility" = "DotnetTest";} + @{"Framework" = "net46"; "TestingFramework" = "net46"; "Utility" = "DotnetTest";}, + @{"Framework" = "net47"; "TestingFramework" = "net47"; "Utility" = "DotnetTest";} ) $ProjectsToPublish=@( diff --git a/Source/Vima.LoggingAbstractor.AppInsights.Tests/UnitTest1.cs b/Source/Vima.LoggingAbstractor.AppInsights.Tests/UnitTest1.cs new file mode 100644 index 0000000..2620ebe --- /dev/null +++ b/Source/Vima.LoggingAbstractor.AppInsights.Tests/UnitTest1.cs @@ -0,0 +1,12 @@ +using Xunit; + +namespace Vima.LoggingAbstractor.AppInsights.Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + } + } +} diff --git a/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj new file mode 100644 index 0000000..74ef4c2 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.0 + Vima.LoggingAbstractor.AppInsights.Tests + Vima.LoggingAbstractor.AppInsights.Tests + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.AppInsights.Tests.xml + ..\ca-tests.ruleset + true + + false + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs b/Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs new file mode 100644 index 0000000..79f82c1 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs @@ -0,0 +1,12 @@ +using Xunit; + +namespace Vima.LoggingAbstractor.Core.Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj new file mode 100644 index 0000000..6aecec6 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.0 + Vima.LoggingAbstractor.Core.Tests + Vima.LoggingAbstractor.Core.Tests + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Core.Tests.xml + true + ..\ca-tests.ruleset + + false + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index acd14f5..6ec34ee 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -1,6 +1,6 @@ - + 1.0.0 1.0.0 Victor Usoltsev @@ -18,9 +18,9 @@ LoggingAbstractor.Core LoggingAbstractor.Core - + - net47;net46;net45;net40;net35;net20;netstandard1.0;netstandard2.0;portable-net40+sl5+win8+wpa81+wp8;portable-net45+win8+wpa81+wp8 + net47;net46;net45;net40;net35;net20;netstandard1.0;netstandard2.0 Vima.LoggingAbstractor.Core Vima.LoggingAbstractor.Core bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Core.xml @@ -28,7 +28,11 @@ true - + + + + + NET46 @@ -37,30 +41,6 @@ NET45 - - PORTABLE45 - .NETPortable - v4.5 - Profile259 - .NETPortable,Version=v0.0,Profile=Profile259 - $(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets - false - - - - NET40 - - - - PORTABLE40 - .NETPortable - v4.0 - Profile328 - .NETPortable,Version=v0.0,Profile=Profile328 - $(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets - false - - NET35 @@ -76,8 +56,4 @@ NETSTANDARD2_0 - - - - diff --git a/Source/Vima.LoggingAbstractor.Raygun.Tests/UnitTest1.cs b/Source/Vima.LoggingAbstractor.Raygun.Tests/UnitTest1.cs new file mode 100644 index 0000000..e0c183a --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Raygun.Tests/UnitTest1.cs @@ -0,0 +1,12 @@ +using Xunit; + +namespace Vima.LoggingAbstractor.Raygun.Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj b/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj new file mode 100644 index 0000000..b146882 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj @@ -0,0 +1,21 @@ + + + + netcoreapp2.0 + Vima.LoggingAbstractor.Raygun.Tests + Vima.LoggingAbstractor.Raygun.Tests + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.Tests.xml + ..\ca-tests.ruleset + true + + false + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.Sentry.Tests/UnitTest1.cs b/Source/Vima.LoggingAbstractor.Sentry.Tests/UnitTest1.cs new file mode 100644 index 0000000..480e4dc --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Sentry.Tests/UnitTest1.cs @@ -0,0 +1,12 @@ +using Xunit; + +namespace Vima.LoggingAbstractor.Sentry.Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj b/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj new file mode 100644 index 0000000..875b0e2 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj @@ -0,0 +1,21 @@ + + + + net47 + Vima.LoggingAbstractor.Sentry.Tests + Vima.LoggingAbstractor.Sentry.Tests + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Sentry.Tests.xml + true + ..\ca-tests.ruleset + + false + + + + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj index d1777c4..4353653 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -23,7 +23,7 @@ net47;net46;net45;net40;net35 Vima.LoggingAbstractor.Sentry Vima.LoggingAbstractor.Sentry - bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Raygun.xml + bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Sentry.xml ..\ca.ruleset true diff --git a/Source/Vima.LoggingAbstractor.sln b/Source/Vima.LoggingAbstractor.sln index d4ff5d3..504d4d6 100644 --- a/Source/Vima.LoggingAbstractor.sln +++ b/Source/Vima.LoggingAbstractor.sln @@ -17,6 +17,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Clients", "Clients", "{9F33 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{ECC3568E-2B5D-4CD9-90E3-8727BA55E179}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.AppInsights.Tests", "Vima.LoggingAbstractor.AppInsights.Tests\Vima.LoggingAbstractor.AppInsights.Tests.csproj", "{E3D4BE5B-E487-40D0-A2A5-CADC98D6EAC4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Raygun.Tests", "Vima.LoggingAbstractor.Raygun.Tests\Vima.LoggingAbstractor.Raygun.Tests.csproj", "{BE9E1277-540B-43AF-B2B0-39C4D54EB4C5}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Sentry.Tests", "Vima.LoggingAbstractor.Sentry.Tests\Vima.LoggingAbstractor.Sentry.Tests.csproj", "{B67216FC-D4EB-4E71-AF39-5A5C84C03505}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vima.LoggingAbstractor.Core.Tests", "Vima.LoggingAbstractor.Core.Tests\Vima.LoggingAbstractor.Core.Tests.csproj", "{1FE06ABE-1840-48FC-B897-86467D804171}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +47,22 @@ Global {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Debug|Any CPU.Build.0 = Debug|Any CPU {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Release|Any CPU.ActiveCfg = Release|Any CPU {5F507DDE-69FC-464F-AC7E-069E2D16D05D}.Release|Any CPU.Build.0 = Release|Any CPU + {E3D4BE5B-E487-40D0-A2A5-CADC98D6EAC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E3D4BE5B-E487-40D0-A2A5-CADC98D6EAC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E3D4BE5B-E487-40D0-A2A5-CADC98D6EAC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E3D4BE5B-E487-40D0-A2A5-CADC98D6EAC4}.Release|Any CPU.Build.0 = Release|Any CPU + {BE9E1277-540B-43AF-B2B0-39C4D54EB4C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE9E1277-540B-43AF-B2B0-39C4D54EB4C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE9E1277-540B-43AF-B2B0-39C4D54EB4C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE9E1277-540B-43AF-B2B0-39C4D54EB4C5}.Release|Any CPU.Build.0 = Release|Any CPU + {B67216FC-D4EB-4E71-AF39-5A5C84C03505}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B67216FC-D4EB-4E71-AF39-5A5C84C03505}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B67216FC-D4EB-4E71-AF39-5A5C84C03505}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B67216FC-D4EB-4E71-AF39-5A5C84C03505}.Release|Any CPU.Build.0 = Release|Any CPU + {1FE06ABE-1840-48FC-B897-86467D804171}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FE06ABE-1840-48FC-B897-86467D804171}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FE06ABE-1840-48FC-B897-86467D804171}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FE06ABE-1840-48FC-B897-86467D804171}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -48,6 +72,10 @@ Global {5CADCE35-9157-4644-A9C2-058D8E8AE8BB} = {9F33D991-BD90-406B-9A62-4D1C7D184368} {CD2797B3-0861-435A-9B36-ADB457E9242A} = {9F33D991-BD90-406B-9A62-4D1C7D184368} {5F507DDE-69FC-464F-AC7E-069E2D16D05D} = {9F33D991-BD90-406B-9A62-4D1C7D184368} + {E3D4BE5B-E487-40D0-A2A5-CADC98D6EAC4} = {ECC3568E-2B5D-4CD9-90E3-8727BA55E179} + {BE9E1277-540B-43AF-B2B0-39C4D54EB4C5} = {ECC3568E-2B5D-4CD9-90E3-8727BA55E179} + {B67216FC-D4EB-4E71-AF39-5A5C84C03505} = {ECC3568E-2B5D-4CD9-90E3-8727BA55E179} + {1FE06ABE-1840-48FC-B897-86467D804171} = {ECC3568E-2B5D-4CD9-90E3-8727BA55E179} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {81C432BA-8657-42A6-BC44-C0D267D70BF8} diff --git a/Source/ca-tests.ruleset b/Source/ca-tests.ruleset new file mode 100644 index 0000000..139474d --- /dev/null +++ b/Source/ca-tests.ruleset @@ -0,0 +1,666 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From e1f70f96da97df0da787667d4fb752eb519b0955 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 20 Feb 2018 20:26:11 +1300 Subject: [PATCH 15/20] Updates LoggerBase. --- ...LoggingAbstractor.AppInsights.Tests.csproj | 7 +++ .../AppInsightsLogger.cs | 10 ++-- .../LoggerBaseTest.cs | 53 +++++++++++++++++++ .../TestLogger.cs | 27 ++++++++++ .../UnitTest1.cs | 12 ----- .../Vima.LoggingAbstractor.Core.Tests.csproj | 6 +++ .../Vima.LoggingAbstractor.Core/LoggerBase.cs | 26 +++++++++ ...Vima.LoggingAbstractor.Raygun.Tests.csproj | 2 + .../RaygunLogger.cs | 10 ++-- ...Vima.LoggingAbstractor.Sentry.Tests.csproj | 2 + .../SentryLogger.cs | 10 ++-- 11 files changed, 138 insertions(+), 27 deletions(-) create mode 100644 Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs create mode 100644 Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs delete mode 100644 Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs diff --git a/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj index 74ef4c2..789f75e 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj @@ -12,10 +12,17 @@ + + + + + + + diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index 203da9e..39d7e49 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -18,13 +18,13 @@ public class AppInsightsLogger : LoggerBase /// Initializes a new instance of the class. /// /// The Application Insights client. - public AppInsightsLogger(TelemetryClient telemetryClient) + /// The minimal logging level. + public AppInsightsLogger(TelemetryClient telemetryClient, LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + : base(minimalLoggingLevel) { _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); } - private static LoggingSeverityLevel MinimalLoggingLevel => LoggingSeverityLevel.Verbose; - /// /// Traces the message. /// @@ -33,7 +33,7 @@ public AppInsightsLogger(TelemetryClient telemetryClient) /// The additional parameters. public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { - if (loggingSeverityLevel < MinimalLoggingLevel) + if (!ShouldBeTraced(loggingSeverityLevel)) { return; } @@ -49,7 +49,7 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// The additional parameters. public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { - if (loggingSeverityLevel < MinimalLoggingLevel) + if (!ShouldBeTraced(loggingSeverityLevel)) { return; } diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs new file mode 100644 index 0000000..dcb5f9b --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using Xunit; + +namespace Vima.LoggingAbstractor.Core.Tests +{ + public sealed class LoggerBaseTest + { + public sealed class ShouldBeTraced + { + [Fact] + public void ShouldReturnCorrectValueInAllCombinationsOfInputs() + { + var minimumLoggingSeverityLevels = Enum.GetValues(typeof(LoggingSeverityLevel)).Cast().ToList(); + var currentLoggingSeverityLevels = Enum.GetValues(typeof(LoggingSeverityLevel)).Cast().ToList(); + + foreach (var minimumLoggingSeverityLevel in minimumLoggingSeverityLevels) + { + foreach (var currentLoggingSeverityLevel in currentLoggingSeverityLevels) + { + // Arrange + TestLogger logger = new TestLogger(minimumLoggingSeverityLevel); + var expectedResult = ShouldClientLogTrace(minimumLoggingSeverityLevel, currentLoggingSeverityLevel); + + // Act + var result = logger.ShouldBeTraced(currentLoggingSeverityLevel); + + // Assert + result.Should().Be(expectedResult, $"current logging level is '{currentLoggingSeverityLevel:G}' and minimal logging level is '{minimumLoggingSeverityLevel.ToString()}'"); + } + } + } + + private static bool ShouldClientLogTrace(LoggingSeverityLevel currentLoggingSeverityLevel, LoggingSeverityLevel minimumLoggingSeverityLevel) + { + Dictionary> allowedLoggingLevelsForMinimumLoggingLevel = + new Dictionary> + { + { LoggingSeverityLevel.Verbose, new List { LoggingSeverityLevel.Verbose } }, + { LoggingSeverityLevel.Information, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information } }, + { LoggingSeverityLevel.Warning, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information, LoggingSeverityLevel.Warning } }, + { LoggingSeverityLevel.Error, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information, LoggingSeverityLevel.Warning, LoggingSeverityLevel.Error } }, + { LoggingSeverityLevel.Critical, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information, LoggingSeverityLevel.Warning, LoggingSeverityLevel.Error, LoggingSeverityLevel.Critical } }, + { LoggingSeverityLevel.None, new List() } + }; + + return allowedLoggingLevelsForMinimumLoggingLevel[minimumLoggingSeverityLevel].Contains(currentLoggingSeverityLevel); + } + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs b/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs new file mode 100644 index 0000000..67d9928 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using Vima.LoggingAbstractor.Core.Parameters; + +namespace Vima.LoggingAbstractor.Core.Tests +{ + public class TestLogger : LoggerBase + { + public TestLogger(LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + : base(minimalLoggingLevel) + { + } + + public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + { + } + + public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + { + } + + public new bool ShouldBeTraced(LoggingSeverityLevel loggingSeverityLevel) + { + return base.ShouldBeTraced(loggingSeverityLevel); + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs b/Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs deleted file mode 100644 index 79f82c1..0000000 --- a/Source/Vima.LoggingAbstractor.Core.Tests/UnitTest1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Xunit; - -namespace Vima.LoggingAbstractor.Core.Tests -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - } - } -} diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj index 6aecec6..dc64d60 100644 --- a/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj @@ -12,10 +12,16 @@ + + + + + + diff --git a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs index 29fc22e..d8d35c7 100644 --- a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs +++ b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs @@ -12,6 +12,17 @@ namespace Vima.LoggingAbstractor.Core /// public abstract class LoggerBase : ILogger { + private readonly LoggingSeverityLevel _minimalLoggingLevel; + + /// + /// Initializes a new instance of the class. + /// + /// The minimal logging level. + protected LoggerBase(LoggingSeverityLevel minimalLoggingLevel) + { + _minimalLoggingLevel = minimalLoggingLevel; + } + /// /// Traces the message. /// @@ -73,5 +84,20 @@ public virtual void TraceException(Exception exception, LoggingSeverityLevel log /// The logging severity level. /// The additional parameters. public abstract void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + + /// + /// Determines whether tracing should be performed. + /// + /// The logging severity level. + /// Value indicating whether tracing should be performed + protected bool ShouldBeTraced(LoggingSeverityLevel loggingSeverityLevel) + { + if (loggingSeverityLevel == LoggingSeverityLevel.None) + { + return false; + } + + return loggingSeverityLevel >= _minimalLoggingLevel; + } } } \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj b/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj index b146882..64b54ff 100644 --- a/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj @@ -12,6 +12,8 @@ + + diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index fa43a44..e6183a9 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -17,13 +17,13 @@ public class RaygunLogger : LoggerBase /// Initializes a new instance of the class. /// /// The raygun client. - public RaygunLogger(RaygunClient raygunClient) + /// The minimal logging level. + public RaygunLogger(RaygunClient raygunClient, LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + : base(minimalLoggingLevel) { _raygunClient = raygunClient ?? throw new ArgumentNullException(nameof(raygunClient)); } - private static LoggingSeverityLevel MinimalLoggingLevel => LoggingSeverityLevel.Verbose; - /// /// Traces the message. /// @@ -32,7 +32,7 @@ public RaygunLogger(RaygunClient raygunClient) /// The additional parameters. public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { - if (loggingSeverityLevel < MinimalLoggingLevel) + if (!ShouldBeTraced(loggingSeverityLevel)) { return; } @@ -49,7 +49,7 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// The additional parameters. public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { - if (loggingSeverityLevel < MinimalLoggingLevel) + if (!ShouldBeTraced(loggingSeverityLevel)) { return; } diff --git a/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj b/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj index 875b0e2..ba096f6 100644 --- a/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj @@ -12,6 +12,8 @@ + + diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index 6f29efb..3df7629 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -18,13 +18,13 @@ public class SentryLogger : LoggerBase /// Initializes a new instance of the class. /// /// The raven client. - public SentryLogger(RavenClient ravenClient) + /// The minimal logging level. + public SentryLogger(RavenClient ravenClient, LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + : base(minimalLoggingLevel) { _ravenClient = ravenClient ?? throw new ArgumentNullException(nameof(ravenClient)); } - private static LoggingSeverityLevel MinimalLoggingLevel => LoggingSeverityLevel.Verbose; - /// /// Traces the message. /// @@ -33,7 +33,7 @@ public SentryLogger(RavenClient ravenClient) /// The additional parameters. public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { - if (loggingSeverityLevel < MinimalLoggingLevel) + if (!ShouldBeTraced(loggingSeverityLevel)) { return; } @@ -49,7 +49,7 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// The additional parameters. public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) { - if (loggingSeverityLevel < MinimalLoggingLevel) + if (!ShouldBeTraced(loggingSeverityLevel)) { return; } From d0105883164d17d7fc7c5334fd77c3645dfd5f15 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Tue, 20 Feb 2018 22:26:11 +1300 Subject: [PATCH 16/20] Renames LoggingSeverityLevel. --- .../AppInsightsLogger.cs | 14 +++---- .../LoggerBaseTest.cs | 35 ++++++++-------- .../TestLogger.cs | 10 ++--- Source/Vima.LoggingAbstractor.Core/ILogger.cs | 16 ++++---- .../Vima.LoggingAbstractor.Core/LoggerBase.cs | 40 +++++++++---------- ...oggingSeverityLevel.cs => LoggingLevel.cs} | 2 +- .../RaygunLogger.cs | 14 +++---- .../SentryLogger.cs | 14 +++---- 8 files changed, 72 insertions(+), 73 deletions(-) rename Source/Vima.LoggingAbstractor.Core/{LoggingSeverityLevel.cs => LoggingLevel.cs} (95%) diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index 39d7e49..e50693b 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -19,7 +19,7 @@ public class AppInsightsLogger : LoggerBase /// /// The Application Insights client. /// The minimal logging level. - public AppInsightsLogger(TelemetryClient telemetryClient, LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + public AppInsightsLogger(TelemetryClient telemetryClient, LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) : base(minimalLoggingLevel) { _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient)); @@ -29,11 +29,11 @@ public AppInsightsLogger(TelemetryClient telemetryClient, LoggingSeverityLevel m /// Traces the message. /// /// The message to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { - if (!ShouldBeTraced(loggingSeverityLevel)) + if (!ShouldBeTraced(loggingLevel)) { return; } @@ -45,11 +45,11 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { - if (!ShouldBeTraced(loggingSeverityLevel)) + if (!ShouldBeTraced(loggingLevel)) { return; } diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs index dcb5f9b..55e9384 100644 --- a/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs +++ b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs @@ -13,40 +13,39 @@ public sealed class ShouldBeTraced [Fact] public void ShouldReturnCorrectValueInAllCombinationsOfInputs() { - var minimumLoggingSeverityLevels = Enum.GetValues(typeof(LoggingSeverityLevel)).Cast().ToList(); - var currentLoggingSeverityLevels = Enum.GetValues(typeof(LoggingSeverityLevel)).Cast().ToList(); + var loggingLevels = Enum.GetValues(typeof(LoggingLevel)).Cast().ToList(); - foreach (var minimumLoggingSeverityLevel in minimumLoggingSeverityLevels) + foreach (var minimalLoggingLevel in loggingLevels) { - foreach (var currentLoggingSeverityLevel in currentLoggingSeverityLevels) + foreach (var currentLoggingLevel in loggingLevels) { // Arrange - TestLogger logger = new TestLogger(minimumLoggingSeverityLevel); - var expectedResult = ShouldClientLogTrace(minimumLoggingSeverityLevel, currentLoggingSeverityLevel); + TestLogger logger = new TestLogger(minimalLoggingLevel); + var expectedResult = ShouldClientLogTrace(minimalLoggingLevel, currentLoggingLevel); // Act - var result = logger.ShouldBeTraced(currentLoggingSeverityLevel); + var result = logger.ShouldBeTraced(currentLoggingLevel); // Assert - result.Should().Be(expectedResult, $"current logging level is '{currentLoggingSeverityLevel:G}' and minimal logging level is '{minimumLoggingSeverityLevel.ToString()}'"); + result.Should().Be(expectedResult, $"current logging level is '{currentLoggingLevel:G}' and minimal logging level is '{minimalLoggingLevel.ToString()}'"); } } } - private static bool ShouldClientLogTrace(LoggingSeverityLevel currentLoggingSeverityLevel, LoggingSeverityLevel minimumLoggingSeverityLevel) + private static bool ShouldClientLogTrace(LoggingLevel currentLoggingLevel, LoggingLevel minimumLoggingLevel) { - Dictionary> allowedLoggingLevelsForMinimumLoggingLevel = - new Dictionary> + Dictionary> allowedLoggingLevelsForMinimumLoggingLevel = + new Dictionary> { - { LoggingSeverityLevel.Verbose, new List { LoggingSeverityLevel.Verbose } }, - { LoggingSeverityLevel.Information, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information } }, - { LoggingSeverityLevel.Warning, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information, LoggingSeverityLevel.Warning } }, - { LoggingSeverityLevel.Error, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information, LoggingSeverityLevel.Warning, LoggingSeverityLevel.Error } }, - { LoggingSeverityLevel.Critical, new List { LoggingSeverityLevel.Verbose, LoggingSeverityLevel.Information, LoggingSeverityLevel.Warning, LoggingSeverityLevel.Error, LoggingSeverityLevel.Critical } }, - { LoggingSeverityLevel.None, new List() } + { LoggingLevel.Verbose, new List { LoggingLevel.Verbose } }, + { LoggingLevel.Information, new List { LoggingLevel.Verbose, LoggingLevel.Information } }, + { LoggingLevel.Warning, new List { LoggingLevel.Verbose, LoggingLevel.Information, LoggingLevel.Warning } }, + { LoggingLevel.Error, new List { LoggingLevel.Verbose, LoggingLevel.Information, LoggingLevel.Warning, LoggingLevel.Error } }, + { LoggingLevel.Critical, new List { LoggingLevel.Verbose, LoggingLevel.Information, LoggingLevel.Warning, LoggingLevel.Error, LoggingLevel.Critical } }, + { LoggingLevel.None, new List() } }; - return allowedLoggingLevelsForMinimumLoggingLevel[minimumLoggingSeverityLevel].Contains(currentLoggingSeverityLevel); + return allowedLoggingLevelsForMinimumLoggingLevel[minimumLoggingLevel].Contains(currentLoggingLevel); } } } diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs b/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs index 67d9928..9202fb7 100644 --- a/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs +++ b/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs @@ -6,22 +6,22 @@ namespace Vima.LoggingAbstractor.Core.Tests { public class TestLogger : LoggerBase { - public TestLogger(LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + public TestLogger(LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) : base(minimalLoggingLevel) { } - public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { } - public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { } - public new bool ShouldBeTraced(LoggingSeverityLevel loggingSeverityLevel) + public new bool ShouldBeTraced(LoggingLevel loggingLevel) { - return base.ShouldBeTraced(loggingSeverityLevel); + return base.ShouldBeTraced(loggingLevel); } } } diff --git a/Source/Vima.LoggingAbstractor.Core/ILogger.cs b/Source/Vima.LoggingAbstractor.Core/ILogger.cs index 6dac132..bbfddc3 100644 --- a/Source/Vima.LoggingAbstractor.Core/ILogger.cs +++ b/Source/Vima.LoggingAbstractor.Core/ILogger.cs @@ -19,16 +19,16 @@ public interface ILogger /// Traces the message. /// /// The message to be logged. - /// The logging severity level. - void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel); + /// The logging level. + void TraceMessage(string message, LoggingLevel loggingLevel); /// /// Traces the message. /// /// The message to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters); /// /// Traces the exception. @@ -40,15 +40,15 @@ public interface ILogger /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. - void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel); + /// The logging level. + void TraceException(Exception exception, LoggingLevel loggingLevel); /// /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters); } } diff --git a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs index d8d35c7..16c8390 100644 --- a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs +++ b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs @@ -12,13 +12,13 @@ namespace Vima.LoggingAbstractor.Core /// public abstract class LoggerBase : ILogger { - private readonly LoggingSeverityLevel _minimalLoggingLevel; + private readonly LoggingLevel _minimalLoggingLevel; /// /// Initializes a new instance of the class. /// /// The minimal logging level. - protected LoggerBase(LoggingSeverityLevel minimalLoggingLevel) + protected LoggerBase(LoggingLevel minimalLoggingLevel) { _minimalLoggingLevel = minimalLoggingLevel; } @@ -29,20 +29,20 @@ protected LoggerBase(LoggingSeverityLevel minimalLoggingLevel) /// The message to be logged. public virtual void TraceMessage(string message) { - TraceMessage(message, LoggingSeverityLevel.Verbose); + TraceMessage(message, LoggingLevel.Verbose); } /// /// Traces the message. /// /// The message to be logged. - /// The logging severity level. - public virtual void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel) + /// The logging level. + public virtual void TraceMessage(string message, LoggingLevel loggingLevel) { #if NET20 - TraceMessage(message, loggingSeverityLevel, new List()); + TraceMessage(message, loggingLevel, new List()); #else - TraceMessage(message, loggingSeverityLevel, Enumerable.Empty()); + TraceMessage(message, loggingLevel, Enumerable.Empty()); #endif } @@ -50,9 +50,9 @@ public virtual void TraceMessage(string message, LoggingSeverityLevel loggingSev /// Traces the message. /// /// The message to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public abstract void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + public abstract void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters); /// /// Traces the exception. @@ -60,20 +60,20 @@ public virtual void TraceMessage(string message, LoggingSeverityLevel loggingSev /// The exception to be logged. public virtual void TraceException(Exception exception) { - TraceException(exception, LoggingSeverityLevel.Critical); + TraceException(exception, LoggingLevel.Critical); } /// /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. - public virtual void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel) + /// The logging level. + public virtual void TraceException(Exception exception, LoggingLevel loggingLevel) { #if NET20 - TraceException(exception, loggingSeverityLevel, new List()); + TraceException(exception, loggingLevel, new List()); #else - TraceException(exception, loggingSeverityLevel, Enumerable.Empty()); + TraceException(exception, loggingLevel, Enumerable.Empty()); #endif } @@ -81,23 +81,23 @@ public virtual void TraceException(Exception exception, LoggingSeverityLevel log /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public abstract void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters); + public abstract void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters); /// /// Determines whether tracing should be performed. /// - /// The logging severity level. + /// The logging level. /// Value indicating whether tracing should be performed - protected bool ShouldBeTraced(LoggingSeverityLevel loggingSeverityLevel) + protected bool ShouldBeTraced(LoggingLevel loggingLevel) { - if (loggingSeverityLevel == LoggingSeverityLevel.None) + if (loggingLevel == LoggingLevel.None) { return false; } - return loggingSeverityLevel >= _minimalLoggingLevel; + return loggingLevel >= _minimalLoggingLevel; } } } \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/LoggingSeverityLevel.cs b/Source/Vima.LoggingAbstractor.Core/LoggingLevel.cs similarity index 95% rename from Source/Vima.LoggingAbstractor.Core/LoggingSeverityLevel.cs rename to Source/Vima.LoggingAbstractor.Core/LoggingLevel.cs index 8df1a49..88b6dc5 100644 --- a/Source/Vima.LoggingAbstractor.Core/LoggingSeverityLevel.cs +++ b/Source/Vima.LoggingAbstractor.Core/LoggingLevel.cs @@ -6,7 +6,7 @@ namespace Vima.LoggingAbstractor.Core /// Represents the severity of the logged message or exception. /// [Flags] - public enum LoggingSeverityLevel + public enum LoggingLevel { /// /// Verbose. diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index e6183a9..3e1d067 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -18,7 +18,7 @@ public class RaygunLogger : LoggerBase /// /// The raygun client. /// The minimal logging level. - public RaygunLogger(RaygunClient raygunClient, LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + public RaygunLogger(RaygunClient raygunClient, LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) : base(minimalLoggingLevel) { _raygunClient = raygunClient ?? throw new ArgumentNullException(nameof(raygunClient)); @@ -28,11 +28,11 @@ public RaygunLogger(RaygunClient raygunClient, LoggingSeverityLevel minimalLoggi /// Traces the message. /// /// The message to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { - if (!ShouldBeTraced(loggingSeverityLevel)) + if (!ShouldBeTraced(loggingLevel)) { return; } @@ -45,11 +45,11 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { - if (!ShouldBeTraced(loggingSeverityLevel)) + if (!ShouldBeTraced(loggingLevel)) { return; } diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index 3df7629..a5c1a6e 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -19,7 +19,7 @@ public class SentryLogger : LoggerBase /// /// The raven client. /// The minimal logging level. - public SentryLogger(RavenClient ravenClient, LoggingSeverityLevel minimalLoggingLevel = LoggingSeverityLevel.Verbose) + public SentryLogger(RavenClient ravenClient, LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) : base(minimalLoggingLevel) { _ravenClient = ravenClient ?? throw new ArgumentNullException(nameof(ravenClient)); @@ -29,11 +29,11 @@ public SentryLogger(RavenClient ravenClient, LoggingSeverityLevel minimalLogging /// Traces the message. /// /// The message to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public override void TraceMessage(string message, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { - if (!ShouldBeTraced(loggingSeverityLevel)) + if (!ShouldBeTraced(loggingLevel)) { return; } @@ -45,11 +45,11 @@ public override void TraceMessage(string message, LoggingSeverityLevel loggingSe /// Traces the exception. /// /// The exception to be logged. - /// The logging severity level. + /// The logging level. /// The additional parameters. - public override void TraceException(Exception exception, LoggingSeverityLevel loggingSeverityLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { - if (!ShouldBeTraced(loggingSeverityLevel)) + if (!ShouldBeTraced(loggingLevel)) { return; } From 79c4ee147071d139d22aa90f54d50c5814d6d6ee Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Wed, 21 Feb 2018 00:23:27 +1300 Subject: [PATCH 17/20] Renames LoggingParameter class. Adds tags to Raygun client. Removes support for .NET2.0 from Core project. --- .../AppInsightsLogger.cs | 8 +-- .../LoggerBaseTest.cs | 4 +- .../LoggingParameterExtensionsTest.cs | 70 +++++++++++++++++++ .../{TestLogger.cs => TestLoggerBase.cs} | 8 +-- .../Extensions/LoggingParameterExtensions.cs | 40 +++++++++++ Source/Vima.LoggingAbstractor.Core/ILogger.cs | 8 +-- .../Vima.LoggingAbstractor.Core/LoggerBase.cs | 22 ++---- .../Parameters/ILoggingAdditionalParameter.cs | 9 --- .../Parameters/ILoggingParameter.cs | 31 ++++++++ .../Parameters/LoggingTagsParameter.cs | 27 ++++--- .../Vima.LoggingAbstractor.Core.csproj | 6 +- .../RaygunLogger.cs | 14 ++-- .../SentryLogger.cs | 8 +-- 13 files changed, 193 insertions(+), 62 deletions(-) create mode 100644 Source/Vima.LoggingAbstractor.Core.Tests/LoggingParameterExtensionsTest.cs rename Source/Vima.LoggingAbstractor.Core.Tests/{TestLogger.cs => TestLoggerBase.cs} (65%) create mode 100644 Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs delete mode 100644 Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs create mode 100644 Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingParameter.cs diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index e50693b..a9ce217 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -30,8 +30,8 @@ public AppInsightsLogger(TelemetryClient telemetryClient, LoggingLevel minimalLo /// /// The message to be logged. /// The logging level. - /// The additional parameters. - public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) + /// The logging parameters. + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { if (!ShouldBeTraced(loggingLevel)) { @@ -46,8 +46,8 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn /// /// The exception to be logged. /// The logging level. - /// The additional parameters. - public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) + /// The logging parameters. + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { if (!ShouldBeTraced(loggingLevel)) { diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs index 55e9384..a407939 100644 --- a/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs +++ b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs @@ -20,11 +20,11 @@ public void ShouldReturnCorrectValueInAllCombinationsOfInputs() foreach (var currentLoggingLevel in loggingLevels) { // Arrange - TestLogger logger = new TestLogger(minimalLoggingLevel); + TestLoggerBase loggerBase = new TestLoggerBase(minimalLoggingLevel); var expectedResult = ShouldClientLogTrace(minimalLoggingLevel, currentLoggingLevel); // Act - var result = logger.ShouldBeTraced(currentLoggingLevel); + var result = loggerBase.ShouldBeTraced(currentLoggingLevel); // Assert result.Should().Be(expectedResult, $"current logging level is '{currentLoggingLevel:G}' and minimal logging level is '{minimalLoggingLevel.ToString()}'"); diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/LoggingParameterExtensionsTest.cs b/Source/Vima.LoggingAbstractor.Core.Tests/LoggingParameterExtensionsTest.cs new file mode 100644 index 0000000..e6c569a --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core.Tests/LoggingParameterExtensionsTest.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using Vima.LoggingAbstractor.Core.Extensions; +using Vima.LoggingAbstractor.Core.Parameters; +using Xunit; + +namespace Vima.LoggingAbstractor.Core.Tests +{ + public sealed class LoggingParameterExtensionsTest + { + public sealed class ExtractTags + { + [Fact(Skip = "Need other logging parameters to exist.")] + public void ShouldHandleNoParameters() + { + // Arrange + // TODO: Create different logging parameter and add here for tests. + + // Act + var tags = new List { }.ExtractTags().ToList(); + + // Assert + tags.Should().BeEmpty(); + } + + [Fact] + public void ShouldHandleNoTagsParameters() + { + // Act + var tags = new List().ExtractTags().ToList(); + + // Assert + tags.Should().BeEmpty(); + } + + [Fact] + public void ShouldHandleOneTagsParameter() + { + // Arrange + string tag = "CustomTag"; + var loggingTagsParameter = new LoggingTagsParameter(new List { tag }); + + // Act + var tags = new List { loggingTagsParameter }.ExtractTags().ToList(); + + // Assert + tags.Count.Should().Be(1); + tags.Should().Contain(tag); + } + + [Fact] + public void ShouldHandleMultipleTagsParameter() + { + // Arrange + var loggingTagsParameter1 = new LoggingTagsParameter(new List { LoggingLevel.Critical }); + var loggingTagsParameter2 = new LoggingTagsParameter(new List { LoggingLevel.None }); + + // Act + var tags = new List { loggingTagsParameter1, loggingTagsParameter2 }.ExtractTags().ToList(); + + // Assert + tags.Count.Should().Be(2); + tags.Should().Contain(LoggingLevel.Critical.ToString("G")); + tags.Should().Contain(LoggingLevel.None.ToString("G")); + } + } + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs b/Source/Vima.LoggingAbstractor.Core.Tests/TestLoggerBase.cs similarity index 65% rename from Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs rename to Source/Vima.LoggingAbstractor.Core.Tests/TestLoggerBase.cs index 9202fb7..e9bffd7 100644 --- a/Source/Vima.LoggingAbstractor.Core.Tests/TestLogger.cs +++ b/Source/Vima.LoggingAbstractor.Core.Tests/TestLoggerBase.cs @@ -4,18 +4,18 @@ namespace Vima.LoggingAbstractor.Core.Tests { - public class TestLogger : LoggerBase + public class TestLoggerBase : LoggerBase { - public TestLogger(LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) + public TestLoggerBase(LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose) : base(minimalLoggingLevel) { } - public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { } - public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { } diff --git a/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs b/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs new file mode 100644 index 0000000..9bd2604 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using Vima.LoggingAbstractor.Core.Parameters; + +namespace Vima.LoggingAbstractor.Core.Extensions +{ + /// + /// Responsible for containing all of the extensions for logging parameters. + /// + public static class LoggingParameterExtensions + { + /// + /// Extracts the tags. + /// + /// The logging parameters. + /// Tags + public static IEnumerable ExtractTags(this IEnumerable parameters) + { + List loggingParameters = parameters + .Where(x => x.LoggingParameterType == LoggingParameterType.Tags) + .ToList(); + + if (!loggingParameters.Any()) + { + return new List(); + } + + List result = new List(); + foreach (var loggingParameter in loggingParameters) + { + if (loggingParameter is ILoggingParameter> tags) + { + result.AddRange(tags.Value); + } + } + + return result.Distinct(); + } + } +} diff --git a/Source/Vima.LoggingAbstractor.Core/ILogger.cs b/Source/Vima.LoggingAbstractor.Core/ILogger.cs index bbfddc3..4ca9f39 100644 --- a/Source/Vima.LoggingAbstractor.Core/ILogger.cs +++ b/Source/Vima.LoggingAbstractor.Core/ILogger.cs @@ -27,8 +27,8 @@ public interface ILogger /// /// The message to be logged. /// The logging level. - /// The additional parameters. - void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters); + /// The logging parameters. + void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters); /// /// Traces the exception. @@ -48,7 +48,7 @@ public interface ILogger /// /// The exception to be logged. /// The logging level. - /// The additional parameters. - void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters); + /// The logging parameters. + void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters); } } diff --git a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs index 16c8390..e4f941f 100644 --- a/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs +++ b/Source/Vima.LoggingAbstractor.Core/LoggerBase.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -#if !NET20 using System.Linq; -#endif using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Core @@ -39,11 +37,7 @@ public virtual void TraceMessage(string message) /// The logging level. public virtual void TraceMessage(string message, LoggingLevel loggingLevel) { -#if NET20 - TraceMessage(message, loggingLevel, new List()); -#else - TraceMessage(message, loggingLevel, Enumerable.Empty()); -#endif + TraceMessage(message, loggingLevel, Enumerable.Empty()); } /// @@ -51,8 +45,8 @@ public virtual void TraceMessage(string message, LoggingLevel loggingLevel) /// /// The message to be logged. /// The logging level. - /// The additional parameters. - public abstract void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters); + /// The logging parameters. + public abstract void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters); /// /// Traces the exception. @@ -70,11 +64,7 @@ public virtual void TraceException(Exception exception) /// The logging level. public virtual void TraceException(Exception exception, LoggingLevel loggingLevel) { -#if NET20 - TraceException(exception, loggingLevel, new List()); -#else - TraceException(exception, loggingLevel, Enumerable.Empty()); -#endif + TraceException(exception, loggingLevel, Enumerable.Empty()); } /// @@ -82,8 +72,8 @@ public virtual void TraceException(Exception exception, LoggingLevel loggingLeve /// /// The exception to be logged. /// The logging level. - /// The additional parameters. - public abstract void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters); + /// The logging parameters. + public abstract void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters); /// /// Determines whether tracing should be performed. diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs deleted file mode 100644 index 811785b..0000000 --- a/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingAdditionalParameter.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Vima.LoggingAbstractor.Core.Parameters -{ - /// - /// Represents additional logging parameter. - /// - public interface ILoggingAdditionalParameter - { - } -} diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingParameter.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingParameter.cs new file mode 100644 index 0000000..66cb11c --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/ILoggingParameter.cs @@ -0,0 +1,31 @@ +namespace Vima.LoggingAbstractor.Core.Parameters +{ + /// + /// Represents logging parameter. + /// + /// Parameter's value type. + public interface ILoggingParameter : ILoggingParameter + { + /// + /// Gets the parameter's value. + /// + /// + /// The parameter's value. + /// + T Value { get; } + } + + /// + /// Represents logging parameter. + /// + public interface ILoggingParameter + { + /// + /// Gets the type of the logging parameter. + /// + /// + /// The type of the logging parameter. + /// + LoggingParameterType LoggingParameterType { get; } + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs index 8d86ed4..7fcfe81 100644 --- a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingTagsParameter.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; +using System.Linq; namespace Vima.LoggingAbstractor.Core.Parameters { /// /// Represents logging tags parameter. /// - public class LoggingTagsParameter : ILoggingAdditionalParameter + public class LoggingTagsParameter : ILoggingParameter> { /// /// Initializes a new instance of the class. @@ -14,23 +15,33 @@ public class LoggingTagsParameter : ILoggingAdditionalParameter /// The tags. public LoggingTagsParameter(IEnumerable tags) { - Tags = tags ?? throw new ArgumentNullException(nameof(tags)); + Value = tags ?? throw new ArgumentNullException(nameof(tags)); } /// - /// Gets the tags. + /// Initializes a new instance of the class. + /// + /// The tags. + public LoggingTagsParameter(IEnumerable tags) + { + IEnumerable enumTags = tags ?? throw new ArgumentNullException(nameof(tags)); + Value = enumTags.Select(x => x.ToString("G")); + } + + /// + /// Gets the parameter's value. /// /// - /// The tags. + /// The parameter's value. /// - public IEnumerable Tags { get; } + public IEnumerable Value { get; } /// - /// Gets the type of the logging parameter type. + /// Gets the type of the logging parameter. /// /// - /// The type of the logging parameter type. + /// The type of the logging parameter. /// - internal LoggingParameterType LoggingParameterType => LoggingParameterType.Tags; + public LoggingParameterType LoggingParameterType => LoggingParameterType.Tags; } } \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index 6ec34ee..6dfd651 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -20,7 +20,7 @@ - net47;net46;net45;net40;net35;net20;netstandard1.0;netstandard2.0 + net47;net46;net45;net40;net35;netstandard1.0;netstandard2.0 Vima.LoggingAbstractor.Core Vima.LoggingAbstractor.Core bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Core.xml @@ -45,10 +45,6 @@ NET35 - - NET20 - - NETSTANDARD1_0 diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index 3e1d067..cefa2ee 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -1,7 +1,9 @@ using System; using System.Collections.Generic; +using System.Linq; using Mindscape.Raygun4Net; using Vima.LoggingAbstractor.Core; +using Vima.LoggingAbstractor.Core.Extensions; using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Raygun @@ -29,8 +31,8 @@ public RaygunLogger(RaygunClient raygunClient, LoggingLevel minimalLoggingLevel /// /// The message to be logged. /// The logging level. - /// The additional parameters. - public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) + /// The logging parameters. + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { if (!ShouldBeTraced(loggingLevel)) { @@ -38,7 +40,7 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn } var messageException = new RaygunMessageException(message); - _raygunClient.Send(messageException); + _raygunClient.Send(messageException, parameters.ExtractTags().ToList()); } /// @@ -46,15 +48,15 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn /// /// The exception to be logged. /// The logging level. - /// The additional parameters. - public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) + /// The logging parameters. + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { if (!ShouldBeTraced(loggingLevel)) { return; } - _raygunClient.Send(exception); + _raygunClient.Send(exception, parameters.ExtractTags().ToList()); } } } diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index a5c1a6e..e018a71 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -30,8 +30,8 @@ public SentryLogger(RavenClient ravenClient, LoggingLevel minimalLoggingLevel = /// /// The message to be logged. /// The logging level. - /// The additional parameters. - public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) + /// The logging parameters. + public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) { if (!ShouldBeTraced(loggingLevel)) { @@ -46,8 +46,8 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn /// /// The exception to be logged. /// The logging level. - /// The additional parameters. - public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) + /// The logging parameters. + public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) { if (!ShouldBeTraced(loggingLevel)) { From 175402ebb104efb3362b5aa146e8d954c84c0991 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Wed, 21 Feb 2018 23:30:21 +1300 Subject: [PATCH 18/20] Adds tags to Sentry and AppInsights clients. --- .../AppInsightsLogger.cs | 17 +++++++++++++++-- .../SentryLogger.cs | 13 +++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index a9ce217..014bd80 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -3,6 +3,7 @@ using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; using Vima.LoggingAbstractor.Core; +using Vima.LoggingAbstractor.Core.Extensions; using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.AppInsights @@ -38,7 +39,9 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn return; } - _telemetryClient.Track(new TraceTelemetry(message)); + var traceTelemetry = new TraceTelemetry(message); + AddTagsToProperties(traceTelemetry, parameters); + _telemetryClient.Track(traceTelemetry); } /// @@ -54,7 +57,17 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev return; } - _telemetryClient.Track(new ExceptionTelemetry(exception)); + var exceptionTelemetry = new ExceptionTelemetry(exception); + AddTagsToProperties(exceptionTelemetry, parameters); + _telemetryClient.Track(exceptionTelemetry); + } + + private static void AddTagsToProperties(ISupportProperties telemetry, IEnumerable parameters) + { + foreach (string tag in parameters.ExtractTags()) + { + telemetry.Properties.Add(tag, tag); + } } } } diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index e018a71..5a2c7ae 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Linq; using SharpRaven; using SharpRaven.Data; using Vima.LoggingAbstractor.Core; +using Vima.LoggingAbstractor.Core.Extensions; using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Sentry @@ -38,7 +40,8 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn return; } - _ravenClient.Capture(new SentryEvent(message)); + Dictionary tags = GenerateTags(parameters); + _ravenClient.Capture(new SentryEvent(message) { Tags = tags }); } /// @@ -54,7 +57,13 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev return; } - _ravenClient.Capture(new SentryEvent(exception)); + Dictionary tags = GenerateTags(parameters); + _ravenClient.Capture(new SentryEvent(exception) { Tags = tags }); + } + + private static Dictionary GenerateTags(IEnumerable parameters) + { + return parameters.ExtractTags().ToDictionary(tag => tag); } } } From 0a57aef666c16c87a79a749f9e8caf2d5e5e8f1a Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Wed, 14 Mar 2018 22:31:06 +1300 Subject: [PATCH 19/20] Adds data parameter. Adds Multilogger. Updates packages. --- ...LoggingAbstractor.AppInsights.Tests.csproj | 6 +- .../AppInsightsLogger.cs | 19 +++- .../IAppInsightsLogger.cs | 12 +++ .../Vima.LoggingAbstractor.AppInsights.csproj | 4 +- .../Vima.LoggingAbstractor.Core.Tests.csproj | 4 +- .../Extensions/LoggingParameterExtensions.cs | 32 ++++++- .../IMultiLogger.cs | 9 ++ .../MultiLogger.cs | 92 +++++++++++++++++++ .../Parameters/LoggingDataParameter.cs | 35 +++++++ .../Parameters/LoggingParameterType.cs | 7 +- .../Vima.LoggingAbstractor.Core.csproj | 1 + ...Vima.LoggingAbstractor.Raygun.Tests.csproj | 4 +- .../IRaygunLogger.cs | 11 +++ .../RaygunLogger.cs | 22 ++++- .../Vima.LoggingAbstractor.Raygun.csproj | 2 +- ...Vima.LoggingAbstractor.Sentry.Tests.csproj | 4 +- .../ISentryLogger.cs | 11 +++ .../SentryLogger.cs | 12 ++- .../Vima.LoggingAbstractor.Sentry.csproj | 4 +- 19 files changed, 262 insertions(+), 29 deletions(-) create mode 100644 Source/Vima.LoggingAbstractor.AppInsights/IAppInsightsLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.Core/IMultiLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.Core/MultiLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.Core/Parameters/LoggingDataParameter.cs create mode 100644 Source/Vima.LoggingAbstractor.Raygun/IRaygunLogger.cs create mode 100644 Source/Vima.LoggingAbstractor.Sentry/ISentryLogger.cs diff --git a/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj index 789f75e..756ce98 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj @@ -13,12 +13,12 @@ - - + + - + diff --git a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs index 014bd80..d976d1d 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs +++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.DataContracts; using Vima.LoggingAbstractor.Core; @@ -11,7 +12,7 @@ namespace Vima.LoggingAbstractor.AppInsights /// /// Represents an instance of an Application Insights logger. /// - public class AppInsightsLogger : LoggerBase + public class AppInsightsLogger : LoggerBase, IAppInsightsLogger { private readonly TelemetryClient _telemetryClient; @@ -40,7 +41,7 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn } var traceTelemetry = new TraceTelemetry(message); - AddTagsToProperties(traceTelemetry, parameters); + AddParametersToProperties(traceTelemetry, parameters); _telemetryClient.Track(traceTelemetry); } @@ -58,16 +59,24 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev } var exceptionTelemetry = new ExceptionTelemetry(exception); - AddTagsToProperties(exceptionTelemetry, parameters); + AddParametersToProperties(exceptionTelemetry, parameters); _telemetryClient.Track(exceptionTelemetry); } - private static void AddTagsToProperties(ISupportProperties telemetry, IEnumerable parameters) + private static void AddParametersToProperties(ISupportProperties telemetry, IEnumerable parameters) { - foreach (string tag in parameters.ExtractTags()) + IEnumerable loggingParameters = parameters.ToList(); + + foreach (string tag in loggingParameters.ExtractTags()) { telemetry.Properties.Add(tag, tag); } + + var dataCount = 0; + foreach (string data in loggingParameters.ExtractData()) + { + telemetry.Properties.Add($"Data #{dataCount++}", data); + } } } } diff --git a/Source/Vima.LoggingAbstractor.AppInsights/IAppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/IAppInsightsLogger.cs new file mode 100644 index 0000000..8dd3970 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.AppInsights/IAppInsightsLogger.cs @@ -0,0 +1,12 @@ +using Vima.LoggingAbstractor.Core; + +namespace Vima.LoggingAbstractor.AppInsights +{ + /// + /// Represents an instance of an Application Insights logger. + /// + /// + public interface IAppInsightsLogger : ILogger + { + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj index 232efb1..8ef7232 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj @@ -20,7 +20,7 @@ - net47;net46;net45;net40;netstandard1.3;netstandard2.0 + net47;net46;net45;netstandard1.3;netstandard2.0 Vima.LoggingAbstractor.AppInsights Vima.LoggingAbstractor.AppInsights bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.AppInsights.xml @@ -30,7 +30,7 @@ - + diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj index dc64d60..d72cd9d 100644 --- a/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj @@ -13,11 +13,11 @@ - + - + diff --git a/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs b/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs index 9bd2604..4467e1e 100644 --- a/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs +++ b/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using Newtonsoft.Json; using Vima.LoggingAbstractor.Core.Parameters; namespace Vima.LoggingAbstractor.Core.Extensions @@ -13,7 +14,7 @@ public static class LoggingParameterExtensions /// Extracts the tags. /// /// The logging parameters. - /// Tags + /// Tag values public static IEnumerable ExtractTags(this IEnumerable parameters) { List loggingParameters = parameters @@ -36,5 +37,34 @@ public static IEnumerable ExtractTags(this IEnumerable + /// Extracts the data values. + /// + /// The logging parameters. + /// Data values + public static IEnumerable ExtractData(this IEnumerable parameters) + { + List loggingParameters = parameters + .Where(x => x.LoggingParameterType == LoggingParameterType.Data) + .ToList(); + + if (!loggingParameters.Any()) + { + return new List(); + } + + List result = new List(); + foreach (var loggingParameter in loggingParameters) + { + if (loggingParameter is ILoggingParameter data) + { + string value = JsonConvert.SerializeObject(data.Value); + result.Add(value); + } + } + + return result; + } } } diff --git a/Source/Vima.LoggingAbstractor.Core/IMultiLogger.cs b/Source/Vima.LoggingAbstractor.Core/IMultiLogger.cs new file mode 100644 index 0000000..459bf91 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/IMultiLogger.cs @@ -0,0 +1,9 @@ +namespace Vima.LoggingAbstractor.Core +{ + /// + /// Responsible for combining multiple loggers at the same time. + /// + public interface IMultiLogger : ILogger + { + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/MultiLogger.cs b/Source/Vima.LoggingAbstractor.Core/MultiLogger.cs new file mode 100644 index 0000000..7815014 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/MultiLogger.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Vima.LoggingAbstractor.Core.Parameters; + +namespace Vima.LoggingAbstractor.Core +{ + /// + /// Responsible for combining multiple loggers at the same time. + /// + public class MultiLogger : IMultiLogger + { + private readonly IEnumerable _loggers; + + /// + /// Initializes a new instance of the class. + /// + /// The loggers used to trace events. + protected MultiLogger(IEnumerable loggers) + { + _loggers = loggers ?? throw new ArgumentNullException(nameof(loggers)); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + public void TraceMessage(string message) + { + TraceMessage(message, LoggingLevel.Verbose); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging level. + public void TraceMessage(string message, LoggingLevel loggingLevel) + { + TraceMessage(message, loggingLevel, Enumerable.Empty()); + } + + /// + /// Traces the message. + /// + /// The message to be logged. + /// The logging level. + /// The logging parameters. + public void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters) + { + IEnumerable loggingParameters = parameters.ToList(); + foreach (var logger in _loggers) + { + logger.TraceMessage(message, loggingLevel, loggingParameters); + } + } + + /// + /// Traces the exception. + /// + /// The exception to be logged. + public void TraceException(Exception exception) + { + TraceException(exception, LoggingLevel.Critical); + } + + /// + /// Traces the exception. + /// + /// The exception to be logged. + /// The logging level. + public void TraceException(Exception exception, LoggingLevel loggingLevel) + { + TraceException(exception, loggingLevel, Enumerable.Empty()); + } + + /// + /// Traces the exception. + /// + /// The exception to be logged. + /// The logging level. + /// The logging parameters. + public void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters) + { + IEnumerable loggingParameters = parameters.ToList(); + foreach (var logger in _loggers) + { + logger.TraceException(exception, loggingLevel, loggingParameters); + } + } + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingDataParameter.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingDataParameter.cs new file mode 100644 index 0000000..2e9d819 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingDataParameter.cs @@ -0,0 +1,35 @@ +using System; + +namespace Vima.LoggingAbstractor.Core.Parameters +{ + /// + /// Represents logging data parameter. + /// + public class LoggingDataParameter : ILoggingParameter + { + /// + /// Initializes a new instance of the class. + /// + /// The data. + public LoggingDataParameter(object data) + { + Value = data ?? throw new ArgumentNullException(nameof(data)); + } + + /// + /// Gets the parameter's value. + /// + /// + /// The parameter's value. + /// + public object Value { get; } + + /// + /// Gets the type of the logging parameter. + /// + /// + /// The type of the logging parameter. + /// + public LoggingParameterType LoggingParameterType => LoggingParameterType.Data; + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs index 82c732b..4fb4d9b 100644 --- a/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs +++ b/Source/Vima.LoggingAbstractor.Core/Parameters/LoggingParameterType.cs @@ -8,6 +8,11 @@ public enum LoggingParameterType /// /// The tags parameter. /// - Tags + Tags, + + /// + /// The data parameter + /// + Data } } \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index 6dfd651..a501c19 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -30,6 +30,7 @@ + diff --git a/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj b/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj index 64b54ff..e3d11bf 100644 --- a/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun.Tests/Vima.LoggingAbstractor.Raygun.Tests.csproj @@ -13,11 +13,11 @@ - + - + diff --git a/Source/Vima.LoggingAbstractor.Raygun/IRaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/IRaygunLogger.cs new file mode 100644 index 0000000..f4ff6ba --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Raygun/IRaygunLogger.cs @@ -0,0 +1,11 @@ +using Vima.LoggingAbstractor.Core; + +namespace Vima.LoggingAbstractor.Raygun +{ + /// + /// Represents an instance of a Raygun logger. + /// + public interface IRaygunLogger : ILogger + { + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs index cefa2ee..5c26794 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs +++ b/Source/Vima.LoggingAbstractor.Raygun/RaygunLogger.cs @@ -11,7 +11,7 @@ namespace Vima.LoggingAbstractor.Raygun /// /// Represents an instance of a Raygun logger. /// - public class RaygunLogger : LoggerBase + public class RaygunLogger : LoggerBase, IRaygunLogger { private readonly RaygunClient _raygunClient; @@ -39,8 +39,10 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn return; } + IEnumerable loggingParameters = parameters.ToList(); var messageException = new RaygunMessageException(message); - _raygunClient.Send(messageException, parameters.ExtractTags().ToList()); + var data = ExtractDataValues(loggingParameters); + _raygunClient.Send(messageException, loggingParameters.ExtractTags().ToList(), data); } /// @@ -56,7 +58,21 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev return; } - _raygunClient.Send(exception, parameters.ExtractTags().ToList()); + IEnumerable loggingParameters = parameters.ToList(); + var data = ExtractDataValues(loggingParameters); + _raygunClient.Send(exception, loggingParameters.ExtractTags().ToList(), data); + } + + private Dictionary ExtractDataValues(IEnumerable parameters) + { + var dataCount = 0; + var dataDictionary = new Dictionary(); + foreach (string data in parameters.ExtractData()) + { + dataDictionary.Add($"Data #{dataCount++}", data); + } + + return dataDictionary; } } } diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj index 894f369..9b626f9 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -31,7 +31,7 @@ - + diff --git a/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj b/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj index ba096f6..6250070 100644 --- a/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry.Tests/Vima.LoggingAbstractor.Sentry.Tests.csproj @@ -13,11 +13,11 @@ - + - + diff --git a/Source/Vima.LoggingAbstractor.Sentry/ISentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/ISentryLogger.cs new file mode 100644 index 0000000..a8eb548 --- /dev/null +++ b/Source/Vima.LoggingAbstractor.Sentry/ISentryLogger.cs @@ -0,0 +1,11 @@ +using Vima.LoggingAbstractor.Core; + +namespace Vima.LoggingAbstractor.Sentry +{ + /// + /// Represents an instance of a Sentry logger. + /// + public interface ISentryLogger : ILogger + { + } +} \ No newline at end of file diff --git a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs index 5a2c7ae..603887d 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs +++ b/Source/Vima.LoggingAbstractor.Sentry/SentryLogger.cs @@ -12,7 +12,7 @@ namespace Vima.LoggingAbstractor.Sentry /// /// Represents an instance of a Sentry logger. /// - public class SentryLogger : LoggerBase + public class SentryLogger : LoggerBase, ISentryLogger { private readonly RavenClient _ravenClient; @@ -40,8 +40,9 @@ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEn return; } - Dictionary tags = GenerateTags(parameters); - _ravenClient.Capture(new SentryEvent(message) { Tags = tags }); + IEnumerable loggingParameters = parameters.ToList(); + Dictionary tags = GenerateTags(loggingParameters); + _ravenClient.Capture(new SentryEvent(message) { Tags = tags, Extra = loggingParameters.ExtractData() }); } /// @@ -57,8 +58,9 @@ public override void TraceException(Exception exception, LoggingLevel loggingLev return; } - Dictionary tags = GenerateTags(parameters); - _ravenClient.Capture(new SentryEvent(exception) { Tags = tags }); + IEnumerable loggingParameters = parameters.ToList(); + Dictionary tags = GenerateTags(loggingParameters); + _ravenClient.Capture(new SentryEvent(exception) { Tags = tags, Extra = loggingParameters.ExtractData() }); } private static Dictionary GenerateTags(IEnumerable parameters) diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj index 4353653..6fdab52 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -20,7 +20,7 @@ - net47;net46;net45;net40;net35 + net47;net46;net45;net40;net35;netstandard2.0 Vima.LoggingAbstractor.Sentry Vima.LoggingAbstractor.Sentry bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.Sentry.xml @@ -30,7 +30,7 @@ - + From d3020b688e05f8451b647a52e598a796b160bdf8 Mon Sep 17 00:00:00 2001 From: Victor Usoltsev Date: Wed, 14 Mar 2018 23:11:22 +1300 Subject: [PATCH 20/20] Sets package versions to 0.1.0. --- .../Vima.LoggingAbstractor.AppInsights.csproj | 4 ++-- .../Vima.LoggingAbstractor.Core.csproj | 4 ++-- .../Vima.LoggingAbstractor.Raygun.csproj | 4 ++-- .../Vima.LoggingAbstractor.Sentry.csproj | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj index 8ef7232..f0c3782 100644 --- a/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj +++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj @@ -1,8 +1,8 @@ - 1.0.0 - 1.0.0 + 0.1.0 + 0.1.0 Victor Usoltsev Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. Copyright © Victor Usoltsev 2018 diff --git a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj index a501c19..1210f15 100644 --- a/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj +++ b/Source/Vima.LoggingAbstractor.Core/Vima.LoggingAbstractor.Core.csproj @@ -1,8 +1,8 @@ - 1.0.0 - 1.0.0 + 0.1.0 + 0.1.0 Victor Usoltsev Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. Copyright © Victor Usoltsev 2018 diff --git a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj index 9b626f9..f60790c 100644 --- a/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj +++ b/Source/Vima.LoggingAbstractor.Raygun/Vima.LoggingAbstractor.Raygun.csproj @@ -1,8 +1,8 @@ - 1.0.0 - 1.0.0 + 0.1.0 + 0.1.0 Victor Usoltsev Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. Copyright © Victor Usoltsev 2018 diff --git a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj index 6fdab52..4a19a1a 100644 --- a/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj +++ b/Source/Vima.LoggingAbstractor.Sentry/Vima.LoggingAbstractor.Sentry.csproj @@ -1,8 +1,8 @@ - 1.0.0 - 1.0.0 + 0.1.0 + 0.1.0 Victor Usoltsev Logging Abstractor is a library for .NET that allows you to swap out logging providers with ease. Copyright © Victor Usoltsev 2018