Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Obvs.Logging.Log4Net/Log4NetLogFactory.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using log4net;
using System.Reflection;
using log4net;

namespace Obvs.Logging.Log4Net
{
public class Log4NetLogFactory : ILoggerFactory
{
public ILogger Create(string name)
{
return new Log4NetLogWrapper(LogManager.GetLogger(name));
return new Log4NetLogWrapper(LogManager.GetLogger(Assembly.GetEntryAssembly() ,name));
}

public ILogger Create<T>()
Expand Down
6 changes: 3 additions & 3 deletions Obvs.Logging.Log4Net/Obvs.Logging.Log4Net.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<Company></Company>
<Copyright>Copyright © Christopher Read 2017</Copyright>
<Version>1.0.0</Version>
Expand All @@ -11,7 +11,7 @@
<Description>log4net logging extension for Obvs</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="2.0.7.0" />
<PackageReference Include="Obvs" Version="4.0.0.1" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Obvs" Version="4.1.0.9" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Obvs.Logging.NLog/Obvs.Logging.NLog.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net461</TargetFrameworks>
<Company></Company>
<Copyright>Copyright © Christopher Read 2017</Copyright>
<Version>1.0.0</Version>
Expand All @@ -11,7 +11,7 @@
<Description>NLog logging extension for Obvs</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.0.0.0" />
<PackageReference Include="Obvs" Version="4.0.0.1" />
<PackageReference Include="NLog" Version="4.4.12" />
<PackageReference Include="Obvs" Version="4.1.0.9" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions Obvs.Logging.Serilog/Configuration/FluentConfigExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Obvs.Configuration;

namespace Obvs.Logging.Serilog.Configuration
{
public static class FluentConfigExtensions
{
public static ICanCreate<TMessage, TCommand, TEvent, TRequest, TResponse> UsingNLog<TMessage, TCommand, TEvent, TRequest, TResponse>(this ICanAddEndpointOrLoggingOrCorrelationOrCreate<TMessage, TCommand, TEvent, TRequest, TResponse> configurator,
Func<IEndpoint<TMessage>, bool> enableLogging = null,
Func<Type, LogLevel> logLevelSend = null,
Func<Type, LogLevel> logLevelReceive = null)
where TMessage : class
where TCommand : class, TMessage
where TEvent : class, TMessage
where TRequest : class, TMessage
where TResponse : class, TMessage
{
return configurator.UsingLogging(new SerilogLoggerFactory(), enableLogging, logLevelSend, logLevelReceive);
}
}
}
12 changes: 12 additions & 0 deletions Obvs.Logging.Serilog/Obvs.Logging.Serilog.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Obvs" Version="4.1.0.9" />
<PackageReference Include="Serilog" Version="2.6.0" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions Obvs.Logging.Serilog/SerilogLoggerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Serilog.Core;

namespace Obvs.Logging.Serilog
{
public class SerilogLoggerFactory : ILoggerFactory
{
public ILogger Create(string name)
{
return new SerilogLoggerWrapper(global::Serilog.Log.ForContext("SourceContext", name));
}

public ILogger Create<T>()
{
return new SerilogLoggerWrapper(global::Serilog.Log.ForContext<T>());
}
}
}
84 changes: 84 additions & 0 deletions Obvs.Logging.Serilog/SerilogLoggerWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using Serilog.Core;

namespace Obvs.Logging.Serilog
{
public class SerilogLoggerWrapper : ILogger
{
private readonly global::Serilog.ILogger _logger;

public SerilogLoggerWrapper(global::Serilog.ILogger logger)
{
_logger = logger;
}

public void Debug(string message, Exception exception = null)
{
if (exception == null)
{
_logger.Debug(message);
}
else
{
_logger.Debug(exception, message);
}
}

public void Info(string message, Exception exception = null)
{
if (exception == null)
{
_logger.Information(message);
}
else
{
_logger.Information(exception, message);
}
}

public void Warn(string message, Exception exception = null)
{
if (exception == null)
{
_logger.Warning(message);
}
else
{
_logger.Warning(exception, message);
}
}

public void Error(string message, Exception exception = null)
{
if (exception == null)
{
_logger.Error(message);
}
else
{
_logger.Error(exception, message);
}
}

public void Log(LogLevel level, string message, Exception exception = null)
{
switch (level)
{
case LogLevel.Debug:
Debug(message, exception);
break;
case LogLevel.Info:
Info(message, exception);
break;
case LogLevel.Warn:
Warn(message, exception);
break;
case LogLevel.Error:
Error(message, exception);
break;
default:
throw new ArgumentOutOfRangeException("level", level, null);
}
}
}
}
12 changes: 7 additions & 5 deletions Obvs.Logging.Tests/Obvs.Logging.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45</TargetFrameworks>
<TargetFrameworks>net461</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Obvs" Version="4.0.0.1" />
<PackageReference Include="log4net" Version="2.0.7.0" />
<PackageReference Include="nunit" Version="3.8.1" />
<PackageReference Include="log4net" Version="2.0.7.0" />
<PackageReference Include="FakeItEasy" Version="4.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="3.1.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Obvs.Logging.NLog\Obvs.Logging.NLog.csproj" />
Expand Down
9 changes: 4 additions & 5 deletions Obvs.Logging.Tests/TestLoggerWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using NUnit.Framework;
using Obvs.Logging.NLog;
using Obvs.Logging.NLog;
using Obvs.Logging.Log4Net;
using Xunit;

namespace Obvs.Logging.Tests
{
[TestFixture]
public class TestLoggerWrapper
{
[Test]
[Fact]
public void ShouldUsesCorrectNameForNLog()
{
MyClass myClass = new MyClass(new NLogLoggerFactory());
myClass.LogSomething();
}

[Test]
[Fact]
public void ShouldUsesCorrectNameForLog4Net()
{
MyClass myClass = new MyClass(new Log4NetLogFactory());
Expand Down
17 changes: 13 additions & 4 deletions Obvs.Logging.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Obvs.Logging.NLog", "Obvs.Logging.NLog\Obvs.Logging.NLog.csproj", "{66CAB382-FF32-49DB-A103-3F6837B0FB0E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Obvs.Logging.NLog", "Obvs.Logging.NLog\Obvs.Logging.NLog.csproj", "{66CAB382-FF32-49DB-A103-3F6837B0FB0E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Obvs.Logging.Log4Net", "Obvs.Logging.Log4Net\Obvs.Logging.Log4Net.csproj", "{1DCAA7CD-7A3D-435C-84FE-B648A3DD9CAC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Obvs.Logging.Log4Net", "Obvs.Logging.Log4Net\Obvs.Logging.Log4Net.csproj", "{1DCAA7CD-7A3D-435C-84FE-B648A3DD9CAC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Obvs.Logging.Tests", "Obvs.Logging.Tests\Obvs.Logging.Tests.csproj", "{BC611C7A-C186-438D-92EB-488B607065B8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Obvs.Logging.Tests", "Obvs.Logging.Tests\Obvs.Logging.Tests.csproj", "{BC611C7A-C186-438D-92EB-488B607065B8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CA58ABB1-E39F-433F-A5AE-DF61554A346A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Obvs.Logging.Serilog", "Obvs.Logging.Serilog\Obvs.Logging.Serilog.csproj", "{2CD63F4A-6398-47DB-8025-AFE9040E7B8E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -29,11 +31,18 @@ Global
{BC611C7A-C186-438D-92EB-488B607065B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC611C7A-C186-438D-92EB-488B607065B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC611C7A-C186-438D-92EB-488B607065B8}.Release|Any CPU.Build.0 = Release|Any CPU
{2CD63F4A-6398-47DB-8025-AFE9040E7B8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CD63F4A-6398-47DB-8025-AFE9040E7B8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CD63F4A-6398-47DB-8025-AFE9040E7B8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CD63F4A-6398-47DB-8025-AFE9040E7B8E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BC611C7A-C186-438D-92EB-488B607065B8} = {CA58ABB1-E39F-433F-A5AE-DF61554A346A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D2638AC0-8D73-44E1-A591-1EE2ECFE49F3}
EndGlobalSection
EndGlobal