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
436 changes: 428 additions & 8 deletions .gitignore

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Source/Sample/Packages.config

This file was deleted.

36 changes: 0 additions & 36 deletions Source/Sample/Properties/AssemblyInfo.cs

This file was deleted.

70 changes: 5 additions & 65 deletions Source/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,73 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2F6882D7-7AEC-4180-A1A0-0A1E90B7AEFA}</ProjectGuid>
<TargetFramework>net481</TargetFramework>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Sample</RootNamespace>
<AssemblyName>Sample</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<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|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\packages\NLog.4.0.0\lib\net40\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="NLog" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\log4net.NLogAppender\log4net.NLogAppender.csproj">
<Project>{6DC26274-8B27-4B4F-8281-F6DB9E51BDEF}</Project>
<Name>log4net.NLogAppender</Name>
</ProjectReference>
<ProjectReference Include="..\log4net.NLogAppender\log4net.NLogAppender.csproj" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
9 changes: 6 additions & 3 deletions Source/Sample/app.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
69 changes: 69 additions & 0 deletions Source/log4net.NLogAppender.Tests/NLogAppenderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using NUnit.Framework;
using System;
using System.Linq;

namespace log4net.Tests
{
[TestFixture]
public class NLogAppenderTest
{
private const string TestLoggerName = "TestLogger";
private const string TestMessage = "Test Message";

private readonly NLog.Targets.MemoryTarget _memoryTarget = new NLog.Targets.MemoryTarget();

[OneTimeSetUp]
public void OneTimeSetUp()
{
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(_memoryTarget, NLog.LogLevel.Trace);

log4net.NLogAppender.Initialize();

// Enable Trace level logging in Log4Net
var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();
hierarchy.Root.Level = log4net.Core.Level.Trace;
}

[SetUp]
public void Setup()
{
_memoryTarget.Logs.Clear();
}

[Test]
public void When_LogTrace_Then_Success()
=> TestLog(
(log, message) => log.Logger.Log(typeof(NLogAppenderTest), log4net.Core.Level.Trace, message, null),
"TRACE");

[Test]
public void When_LogDebug_Then_Success()
=> TestLog((log, message) => log.Debug(message), "DEBUG");

[Test]
public void When_LogInfo_Then_Success()
=> TestLog((log, message) => log.Info(message), "INFO");

[Test]
public void When_LogWarn_Then_Success()
=> TestLog((log, message) => log.Warn(message), "WARN");

[Test]
public void When_LogError_Then_Success()
=> TestLog((log, message) => log.Error(message), "ERROR");

[Test]
public void When_LogFatal_Then_Success()
=> TestLog((log, message) => log.Fatal(message), "FATAL");

public void TestLog(Action<ILog, string> writeLogMessage, string logLevel)
{
var log = log4net.LogManager.GetLogger(TestLoggerName);

writeLogMessage.Invoke(log, TestMessage);

Assert.That(_memoryTarget.Logs.Count, Is.EqualTo(1));
Assert.That(_memoryTarget.Logs.Single(), Does.Contain($"|{logLevel}|{TestLoggerName}|{TestMessage}"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net35;net462;net481;net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
<RootNamespace>log4net.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\log4net.NLogAppender\log4net.NLogAppender.csproj" />
</ItemGroup>

</Project>
5 changes: 0 additions & 5 deletions Source/log4net.NLogAppender/Packages.config

This file was deleted.

36 changes: 0 additions & 36 deletions Source/log4net.NLogAppender/Properties/AssemblyInfo.cs

This file was deleted.

65 changes: 6 additions & 59 deletions Source/log4net.NLogAppender/log4net.NLogAppender.csproj
Original file line number Diff line number Diff line change
@@ -1,65 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6DC26274-8B27-4B4F-8281-F6DB9E51BDEF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworks>netstandard2.0;net35;net462</TargetFrameworks>
<Version>2.0.0</Version>
<RootNamespace>log4net</RootNamespace>
<AssemblyName>log4net.NLogAppender</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<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|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\packages\log4net.2.0.3\lib\net35-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\packages\NLog.4.0.0\lib\net35\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="NLogAppender.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<None Include="packages.config" />
<PackageReference Include="log4net" Version="2.0.10" />
<PackageReference Include="NLog" Version="4.5.0" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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>
18 changes: 9 additions & 9 deletions log4net.NLogAppender.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
<projectUrl>https://github.com/lanwin/log4net.NLogAppender</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>An NLog appender for log4net.</summary>
<description>
Its a bridge between NLog and log4net. It hands all log4net logging events over to NLog.
So you could use any lib which uses log4net without even using log4net yourself.
Simply call the following line and you are done:
NLogAppender.Initialize();
<description>
Its a bridge between NLog and log4net. It hands all log4net logging events over to NLog.
So you could use any lib which uses log4net without even using log4net yourself.

Simply call the following line and you are done:

NLogAppender.Initialize();
</description>
<language>en-US</language>
<tags>logging nlog log4net appender bridge</tags>
<dependencies>
<dependency id="NLog" version="[3.0.0,)" />
<dependency id="log4net" version="[2.0.0,)" />
<dependency id="NLog" version="[4.5.0,)" />
<dependency id="log4net" version="[2.0.10,)" />
</dependencies>
</metadata>
<files>
Expand Down
Loading