Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log4net logging adapter support #1389

Merged
merged 1 commit into from
Dec 8, 2015
Merged
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
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Target "CopyOutput" <| fun _ ->
"contrib/loggers/Akka.Logger.slf4net"
"contrib/loggers/Akka.Logger.NLog"
"contrib/loggers/Akka.Logger.Serilog"
"contrib/loggers/Akka.Logger.log4net"
"contrib/dependencyinjection/Akka.DI.Core"
"contrib/dependencyinjection/Akka.DI.AutoFac"
"contrib/dependencyinjection/Akka.DI.CastleWindsor"
Expand Down
11 changes: 11 additions & 0 deletions src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Serialization.TestKit"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Serialization.WireTests", "contrib\serializers\Akka.Serialization.WireTests\Akka.Serialization.WireTests.csproj", "{402FA351-D6C6-40FD-8868-F07156035919}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Logger.log4net", "contrib\loggers\Akka.Logger.log4net\Akka.Logger.log4net.csproj", "{DAEC9503-CA75-433F-83DE-E28965D94D56}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Mono|Any CPU = Debug Mono|Any CPU
Expand Down Expand Up @@ -854,6 +856,14 @@ Global
{402FA351-D6C6-40FD-8868-F07156035919}.Release Mono|Any CPU.Build.0 = Release|Any CPU
{402FA351-D6C6-40FD-8868-F07156035919}.Release|Any CPU.ActiveCfg = Release|Any CPU
{402FA351-D6C6-40FD-8868-F07156035919}.Release|Any CPU.Build.0 = Release|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Debug Mono|Any CPU.ActiveCfg = Debug|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Debug Mono|Any CPU.Build.0 = Debug|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Release Mono|Any CPU.ActiveCfg = Release|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Release Mono|Any CPU.Build.0 = Release|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAEC9503-CA75-433F-83DE-E28965D94D56}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -957,5 +967,6 @@ Global
{B47CA568-40CF-48DE-B87E-31BD400EBB08} = {0E55F1F8-E212-43D7-A0C0-ACEA9794B0D7}
{CAA97041-CFC0-4081-9BD2-8B139E62A611} = {0E55F1F8-E212-43D7-A0C0-ACEA9794B0D7}
{402FA351-D6C6-40FD-8868-F07156035919} = {0E55F1F8-E212-43D7-A0C0-ACEA9794B0D7}
{DAEC9503-CA75-433F-83DE-E28965D94D56} = {FFEC736B-EDA3-433C-8564-7C14676601A1}
EndGlobalSection
EndGlobal
70 changes: 70 additions & 0 deletions src/contrib/loggers/Akka.Logger.log4net/Akka.Logger.log4net.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DAEC9503-CA75-433F-83DE-E28965D94D56}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Akka.Logger.log4net</RootNamespace>
<AssemblyName>Akka.Logger.log4net</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Akka.Logger.log4net.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Log4NetLogger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\core\Akka\Akka.csproj">
<Project>{5deddf90-37f0-48d3-a0b0-a5cbd8a7e377}</Project>
<Name>Akka</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Akka.Logger.log4net.nuspec" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
20 changes: 20 additions & 0 deletions src/contrib/loggers/Akka.Logger.log4net/Akka.Logger.log4net.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>@project@</id>
<title>@project@@title@</title>
<version>@build.number@</version>
<authors>@authors@</authors>
<owners>@authors@</owners>
<description>log4net logging adapter for Akka.NET</description>
<licenseUrl>https://github.com/akkadotnet/akka.net/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/akkadotnet/akka.net</projectUrl>
<iconUrl>http://getakka.net/images/AkkaNetLogo.Normal.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>@releaseNotes@</releaseNotes>
<copyright>@copyright@</copyright>
<tags>@tags@ log4net</tags>
@dependencies@
@references@
</metadata>
</package>
47 changes: 47 additions & 0 deletions src/contrib/loggers/Akka.Logger.log4net/Log4NetLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------
// <copyright file="Log4NetLogger.cs" company="Akka.NET Project">
// Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
// Copyright (C) 2013-2015 Akka.NET project <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using System;
using Akka.Actor;
using Akka.Event;
using log4net;

namespace Akka.Logger.log4net
{
/// <summary>
/// This class is used to receive log events and sends them to
/// the configured log4net logger. The following log events are
/// recognized: <see cref="Debug"/>, <see cref="Info"/>,
/// <see cref="Warning"/> and <see cref="Error"/>.
/// </summary>
public class Log4NetLogger : ReceiveActor
{
private readonly ILoggingAdapter _log = Context.GetLogger();

private static void Log(LogEvent logEvent, Action<ILog> logStatement)
{
var logger = LogManager.GetLogger(logEvent.LogClass.FullName);
logStatement(logger);
}

/// <summary>
/// Initializes a new instance of the <see cref="Log4NetLogger"/> class.
/// </summary>
public Log4NetLogger()
{
Receive<Error>(m => Log(m, logger => logger.Error(string.Format("{0}", m.Message), m.Cause)));
Receive<Warning>(m => Log(m, logger => logger.WarnFormat("{0}", m.Message)));
Receive<Info>(m => Log(m, logger => logger.InfoFormat("{0}", m.Message)));
Receive<Debug>(m => Log(m, logger => logger.DebugFormat("{0}", m.Message)));
Receive<InitializeLogger>(m =>
{
_log.Info("log4net started");
Sender.Tell(new LoggerInitialized());
});
}
}
}
26 changes: 26 additions & 0 deletions src/contrib/loggers/Akka.Logger.log4net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//-----------------------------------------------------------------------
// <copyright file="AssemblyInfo.cs" company="Akka.NET Project">
// Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
// Copyright (C) 2013-2015 Akka.NET project <https://github.com/akkadotnet/akka.net>
// </copyright>
//-----------------------------------------------------------------------

using System.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Akka.Logger.log4net")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyProduct("Akka.Logger.log4net")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("96446c5f-f8af-4e23-ae85-bc3eae49c7b2")]
[assembly: log4net.Config.XmlConfigurator]
4 changes: 4 additions & 0 deletions src/contrib/loggers/Akka.Logger.log4net/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.3" targetFramework="net45" />
</packages>