diff --git a/Scripts/Build.ps1 b/Scripts/Build.ps1
index fcc0fc1..5afe620 100644
--- a/Scripts/Build.ps1
+++ b/Scripts/Build.ps1
@@ -25,11 +25,15 @@ 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=@(
- "$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.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..756ce98
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.AppInsights.Tests/Vima.LoggingAbstractor.AppInsights.Tests.csproj
@@ -0,0 +1,28 @@
+
+
+
+ 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.AppInsights/AppInsightsLogger.cs b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs
new file mode 100644
index 0000000..d976d1d
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.AppInsights/AppInsightsLogger.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+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
+{
+ ///
+ /// Represents an instance of an Application Insights logger.
+ ///
+ public class AppInsightsLogger : LoggerBase, IAppInsightsLogger
+ {
+ private readonly TelemetryClient _telemetryClient;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The Application Insights client.
+ /// The minimal logging level.
+ public AppInsightsLogger(TelemetryClient telemetryClient, LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose)
+ : base(minimalLoggingLevel)
+ {
+ _telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
+ }
+
+ ///
+ /// Traces the message.
+ ///
+ /// The message to be logged.
+ /// The logging level.
+ /// The logging parameters.
+ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters)
+ {
+ if (!ShouldBeTraced(loggingLevel))
+ {
+ return;
+ }
+
+ var traceTelemetry = new TraceTelemetry(message);
+ AddParametersToProperties(traceTelemetry, parameters);
+ _telemetryClient.Track(traceTelemetry);
+ }
+
+ ///
+ /// Traces the exception.
+ ///
+ /// The exception to be logged.
+ /// The logging level.
+ /// The logging parameters.
+ public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters)
+ {
+ if (!ShouldBeTraced(loggingLevel))
+ {
+ return;
+ }
+
+ var exceptionTelemetry = new ExceptionTelemetry(exception);
+ AddParametersToProperties(exceptionTelemetry, parameters);
+ _telemetryClient.Track(exceptionTelemetry);
+ }
+
+ private static void AddParametersToProperties(ISupportProperties telemetry, IEnumerable parameters)
+ {
+ 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
new file mode 100644
index 0000000..f0c3782
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.AppInsights/Vima.LoggingAbstractor.AppInsights.csproj
@@ -0,0 +1,41 @@
+
+
+
+ 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
+ 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;netstandard1.3;netstandard2.0
+ Vima.LoggingAbstractor.AppInsights
+ Vima.LoggingAbstractor.AppInsights
+ bin\$(Configuration)\$(TargetFramework)\Vima.LoggingAbstractor.AppInsights.xml
+ ..\ca.ruleset
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs
new file mode 100644
index 0000000..a407939
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.Core.Tests/LoggerBaseTest.cs
@@ -0,0 +1,52 @@
+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 loggingLevels = Enum.GetValues(typeof(LoggingLevel)).Cast().ToList();
+
+ foreach (var minimalLoggingLevel in loggingLevels)
+ {
+ foreach (var currentLoggingLevel in loggingLevels)
+ {
+ // Arrange
+ TestLoggerBase loggerBase = new TestLoggerBase(minimalLoggingLevel);
+ var expectedResult = ShouldClientLogTrace(minimalLoggingLevel, currentLoggingLevel);
+
+ // Act
+ var result = loggerBase.ShouldBeTraced(currentLoggingLevel);
+
+ // Assert
+ result.Should().Be(expectedResult, $"current logging level is '{currentLoggingLevel:G}' and minimal logging level is '{minimalLoggingLevel.ToString()}'");
+ }
+ }
+ }
+
+ private static bool ShouldClientLogTrace(LoggingLevel currentLoggingLevel, LoggingLevel minimumLoggingLevel)
+ {
+ Dictionary> allowedLoggingLevelsForMinimumLoggingLevel =
+ new Dictionary>
+ {
+ { 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[minimumLoggingLevel].Contains(currentLoggingLevel);
+ }
+ }
+ }
+}
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/TestLoggerBase.cs b/Source/Vima.LoggingAbstractor.Core.Tests/TestLoggerBase.cs
new file mode 100644
index 0000000..e9bffd7
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.Core.Tests/TestLoggerBase.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using Vima.LoggingAbstractor.Core.Parameters;
+
+namespace Vima.LoggingAbstractor.Core.Tests
+{
+ public class TestLoggerBase : LoggerBase
+ {
+ public TestLoggerBase(LoggingLevel minimalLoggingLevel = LoggingLevel.Verbose)
+ : base(minimalLoggingLevel)
+ {
+ }
+
+ public override void TraceMessage(string message, LoggingLevel loggingLevel, IEnumerable parameters)
+ {
+ }
+
+ public override void TraceException(Exception exception, LoggingLevel loggingLevel, IEnumerable parameters)
+ {
+ }
+
+ public new bool ShouldBeTraced(LoggingLevel loggingLevel)
+ {
+ return base.ShouldBeTraced(loggingLevel);
+ }
+ }
+}
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..d72cd9d
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.Core.Tests/Vima.LoggingAbstractor.Core.Tests.csproj
@@ -0,0 +1,27 @@
+
+
+
+ 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/Extensions/LoggingParameterExtensions.cs b/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs
new file mode 100644
index 0000000..4467e1e
--- /dev/null
+++ b/Source/Vima.LoggingAbstractor.Core/Extensions/LoggingParameterExtensions.cs
@@ -0,0 +1,70 @@
+using System.Collections.Generic;
+using System.Linq;
+using Newtonsoft.Json;
+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.
+ /// Tag values
+ 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();
+ }
+
+ ///
+ /// 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