IGNITE-3279 .NET: NLog logger
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1c82cd04 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1c82cd04 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1c82cd04 Branch: refs/heads/ignite-2788 Commit: 1c82cd04fadc61ab5da02e1d395aedfb28a039da Parents: ae4ae71 Author: Pavel Tupitsyn <[email protected]> Authored: Tue Aug 23 13:28:40 2016 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Mon Oct 3 14:08:01 2016 +0300 ---------------------------------------------------------------------- .../Apache.Ignite.Core.Tests.NuGet.csproj | 18 +- .../Apache.Ignite.Core.Tests.NuGet/NLogTest.cs | 82 +++++++++ .../packages.config | 13 +- .../Apache.Ignite.Core.Tests.csproj | 13 +- .../IgniteConfigurationSerializerTest.cs | 3 +- .../Log/NLogLoggerTest.cs | 166 +++++++++++++++++++ .../Apache.Ignite.NLog.csproj | 74 +++++++++ .../Apache.Ignite.NLog.nuspec | 50 ++++++ .../Apache.Ignite.NLog/Apache.Ignite.NLog.snk | Bin 0 -> 596 bytes .../Apache.Ignite.NLog/IgniteNLogLogger.cs | 125 ++++++++++++++ .../Properties/AssemblyInfo.cs | 40 +++++ .../dotnet/Apache.Ignite.NLog/packages.config | 4 + modules/platforms/dotnet/Apache.Ignite.sln | 14 ++ 13 files changed, 589 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/Apache.Ignite.Core.Tests.NuGet.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/Apache.Ignite.Core.Tests.NuGet.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/Apache.Ignite.Core.Tests.NuGet.csproj index 8c4c46b..f3f917e 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/Apache.Ignite.Core.Tests.NuGet.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/Apache.Ignite.Core.Tests.NuGet.csproj @@ -72,17 +72,26 @@ <ItemGroup> <Reference Include="Apache.Ignite.Core"> <SpecificVersion>False</SpecificVersion> - <HintPath>packages\Apache.Ignite.1.6.0\lib\net40\Apache.Ignite.Core.dll</HintPath> + <HintPath>packages\Apache.Ignite.1.8.0\lib\net40\Apache.Ignite.Core.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="Apache.Ignite.Linq"> <SpecificVersion>False</SpecificVersion> - <HintPath>packages\Apache.Ignite.Linq.1.6.0\lib\net40\Apache.Ignite.Linq.dll</HintPath> + <HintPath>packages\Apache.Ignite.Linq.1.8.0\lib\net40\Apache.Ignite.Linq.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="Apache.Ignite.AspNet"> <SpecificVersion>False</SpecificVersion> - <HintPath>packages\Apache.Ignite.AspNet.1.6.0\lib\net40\Apache.Ignite.AspNet.dll</HintPath> + <HintPath>packages\Apache.Ignite.AspNet.1.8.0\lib\net40\Apache.Ignite.AspNet.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="Apache.Ignite.NLog"> + <SpecificVersion>False</SpecificVersion> + <HintPath>packages\Apache.Ignite.NLog.1.8.0\lib\net40\Apache.Ignite.NLog.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> + <HintPath>packages\NLog.4.3.7\lib\net40\NLog.dll</HintPath> <Private>True</Private> </Reference> <Reference Include="nunit-console-runner"> @@ -103,6 +112,7 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="NLogTest.cs" /> <Compile Include="AspNetTest.cs" /> <Compile Include="ComputeTest.cs" /> <Compile Include="SchemaTest.cs" /> @@ -132,7 +142,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PostBuildEvent>if not exist "$(TargetDir)Libs" md "$(TargetDir)Libs" -xcopy /s /y "$(SolutionDir)packages\Apache.Ignite.1.6.0\Libs\*.*" "$(TargetDir)Libs"</PostBuildEvent> +xcopy /s /y "$(SolutionDir)packages\Apache.Ignite.1.8.0\Libs\*.*" "$(TargetDir)Libs"</PostBuildEvent> </PropertyGroup> <PropertyGroup> <PreBuildEvent> http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/NLogTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/NLogTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/NLogTest.cs new file mode 100644 index 0000000..d3c58e1 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/NLogTest.cs @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Tests.NuGet +{ + using System.Linq; + using Apache.Ignite.NLog; + using global::NLog; + using global::NLog.Config; + using global::NLog.Layouts; + using global::NLog.Targets; + using NUnit.Framework; + + /// <summary> + /// NLog test. + /// </summary> + public class NLogTest + { + /// <summary> + /// The log target. + /// </summary> + private MemoryTarget _logTarget; + + /// <summary> + /// Test set up. + /// </summary> + [SetUp] + public void SetUp() + { + var cfg = new LoggingConfiguration(); + + _logTarget = new MemoryTarget("mem") + { + Layout = new SimpleLayout("${Logger}|${Level}|${Message}|${exception}|${all-event-properties}") + }; + + cfg.AddTarget(_logTarget); + + cfg.AddRule(LogLevel.Trace, LogLevel.Error, _logTarget); + + LogManager.Configuration = cfg; + } + + /// <summary> + /// Tests the logger with Ignite. + /// </summary> + [Test] + public void TestIgniteStartup() + { + var cfg = new IgniteConfiguration + { + DiscoverySpi = TestUtil.GetLocalDiscoverySpi(), + Logger = new IgniteNLogLogger(LogManager.GetCurrentClassLogger()) + }; + + using (Ignition.Start(cfg)) + { + Assert.IsTrue(_logTarget.Logs.Contains( + string.Format("|Debug|Starting Ignite.NET {0}||", typeof(Ignition).Assembly.GetName().Version))); + + Assert.IsTrue(_logTarget.Logs.Any(x => x.Contains(">>> Topology snapshot."))); + } + + Assert.IsTrue(_logTarget.Logs.Contains( + "org.apache.ignite.internal.IgniteKernal|Debug|Grid is stopping.||")); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/packages.config ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/packages.config b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/packages.config index 88d9cc2..30e71a1 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/packages.config +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests.NuGet/packages.config @@ -1,5 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> - <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,11 +15,13 @@ See the License for the specific language governing permissions and limitations under the License. --> - <packages> - <package id="Apache.Ignite" version="1.6.0" targetFramework="net40" /> - <package id="Apache.Ignite.Linq" version="1.6.0" targetFramework="net40" /> - <package id="Apache.Ignite.AspNet" version="1.6.0" targetFramework="net40" /> - <package id="Apache.Ignite.Schema" version="1.6.0" targetFramework="net40" /> + <package id="Apache.Ignite" version="1.8.0" targetFramework="net40" /> + <package id="Apache.Ignite.AspNet" version="1.8.0" targetFramework="net40" /> + <package id="Apache.Ignite.Linq" version="1.8.0" targetFramework="net40" /> + <package id="Apache.Ignite.NLog" version="1.8.0" targetFramework="net40" /> + <package id="Apache.Ignite.Schema" version="1.8.0" targetFramework="net40" /> + <package id="NLog" version="4.3.7" targetFramework="net40" /> + <package id="NUnit.Runners" version="2.6.3" targetFramework="net40" /> <package id="Remotion.Linq" version="2.0.1" targetFramework="net40" /> </packages> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj index 2c6150c..ef62498 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj @@ -38,8 +38,12 @@ </PropertyGroup> <ItemGroup> <Reference Include="Microsoft.CSharp" /> - <Reference Include="nunit-console-runner"> - <HintPath>..\libs\nunit-console-runner.dll</HintPath> + <Reference Include="NLog"> + <HintPath>..\packages\NLog.4.3.7\lib\net40\NLog.dll</HintPath> + </Reference> + <Reference Include="nunit-console-runner, Version=2.6.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\packages\NUnit.Runners.2.6.3\tools\lib\nunit-console-runner.dll</HintPath> </Reference> <Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> @@ -54,6 +58,7 @@ </ItemGroup> <ItemGroup> <Compile Include="Log\DefaultLoggerTest.cs" /> + <Compile Include="Log\NLogLoggerTest.cs" /> <Compile Include="TestAppConfig.cs" /> <Compile Include="Binary\BinaryBuilderSelfTestFullFooter.cs" /> <Compile Include="Binary\BinaryCompactFooterInteropTest.cs" /> @@ -175,6 +180,10 @@ <Project>{5b571661-17f4-4f29-8c7d-0edb38ca9b55}</Project> <Name>Apache.Ignite.Linq</Name> </ProjectReference> + <ProjectReference Include="..\Apache.Ignite.NLog\Apache.Ignite.NLog.csproj"> + <Project>{C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}</Project> + <Name>Apache.Ignite.NLog</Name> + </ProjectReference> <ProjectReference Include="..\Apache.Ignite\Apache.Ignite.csproj"> <Project>{27F7F3C6-BDDE-43A9-B565-856F8395A04B}</Project> <Name>Apache.Ignite</Name> http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs index beb1e8d..bb703f5 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs @@ -46,6 +46,7 @@ namespace Apache.Ignite.Core.Tests using Apache.Ignite.Core.Log; using Apache.Ignite.Core.Tests.Binary; using Apache.Ignite.Core.Transactions; + using Apache.Ignite.NLog; using NUnit.Framework; /// <summary> @@ -549,7 +550,7 @@ namespace Apache.Ignite.Core.Tests }, IsLateAffinityAssignment = false, SpringConfigUrl = "test", - Logger = new TestLogger() + Logger = new IgniteNLogLogger() }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/NLogLoggerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/NLogLoggerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/NLogLoggerTest.cs new file mode 100644 index 0000000..7806ecd --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/NLogLoggerTest.cs @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Tests.Log +{ + using System; + using System.Globalization; + using System.Linq; + using Apache.Ignite.Core.Log; + using Apache.Ignite.NLog; + using global::NLog; + using global::NLog.Config; + using global::NLog.Layouts; + using global::NLog.Targets; + using NUnit.Framework; + using LogLevel = Apache.Ignite.Core.Log.LogLevel; + + /// <summary> + /// Tests the NLog integration. + /// </summary> + public class NLogLoggerTest + { + /** */ + private MemoryTarget _logTarget; + + /// <summary> + /// Test set up. + /// </summary> + [SetUp] + public void SetUp() + { + var cfg = new LoggingConfiguration(); + + _logTarget = new MemoryTarget("mem") + { + Layout = new SimpleLayout("${Logger}|${Level}|${Message}|${exception}|${all-event-properties}") + }; + + cfg.AddTarget(_logTarget); + + cfg.AddRule(global::NLog.LogLevel.Trace, global::NLog.LogLevel.Error, _logTarget); + + LogManager.Configuration = cfg; + } + + /// <summary> + /// Tests the log level conversion. + /// </summary> + [Test] + public void TestLogLevelConversion() + { + var levels = new[] { LogLevel.Trace, LogLevel.Info, LogLevel.Debug, LogLevel.Warn, LogLevel.Error }; + + var nLogger = new IgniteNLogLogger(LogManager.GetCurrentClassLogger()); + + foreach (var igniteLevel in levels) + { + var nlogLevel = IgniteNLogLogger.ConvertLogLevel(igniteLevel); + + Assert.AreEqual(igniteLevel.ToString(), nlogLevel.ToString()); + + + Assert.IsTrue(nLogger.IsEnabled(igniteLevel)); + } + } + + /// <summary> + /// Tests the logger in isolated environment. + /// </summary> + [Test] + public void TestLogging() + { + var nLogger = new IgniteNLogLogger(); + + // All parameters. + nLogger.Log(LogLevel.Trace, "msg{0}", new object[] {1}, CultureInfo.InvariantCulture, "category", + "java-err", new Exception("myException")); + + Assert.AreEqual("category|Trace|msg1|myException|nativeErrorInfo=java-err", GetLastLog()); + + // No Java error. + nLogger.Log(LogLevel.Info, "msg{0}", new object[] { 1 }, CultureInfo.InvariantCulture, "category", + null, new Exception("myException")); + + Assert.AreEqual("category|Info|msg1|myException|", GetLastLog()); + + // No exception. + nLogger.Log(LogLevel.Debug, "msg{0}", new object[] { 1 }, CultureInfo.InvariantCulture, "category", + null, null); + + Assert.AreEqual("category|Debug|msg1||", GetLastLog()); + + // No params. + nLogger.Log(LogLevel.Warn, "msg{0}", null, CultureInfo.InvariantCulture, "category", null, null); + + Assert.AreEqual("category|Warn|msg{0}||", GetLastLog()); + + // No formatter. + nLogger.Log(LogLevel.Error, "msg{0}", null, null, "category", null, null); + + Assert.AreEqual("category|Error|msg{0}||", GetLastLog()); + + // No category. + nLogger.Log(LogLevel.Error, "msg{0}", null, null, null, null, null); + + Assert.AreEqual("|Error|msg{0}||", GetLastLog()); + + // No message. + nLogger.Log(LogLevel.Error, null, null, null, null, null, null); + + Assert.AreEqual("|Error|||", GetLastLog()); + } + + /// <summary> + /// Tests the logger with Ignite. + /// </summary> + [Test] + public void TestIgniteStartup() + { + var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration()) + { + Logger = new IgniteNLogLogger(LogManager.GetLogger("foo")) + }; + + using (var ignite = Ignition.Start(cfg)) + { + Assert.IsTrue(_logTarget.Logs.Contains( + string.Format("|Debug|Starting Ignite.NET {0}||", typeof(Ignition).Assembly.GetName().Version))); + + Assert.IsTrue(_logTarget.Logs.Any(x => x.Contains(">>> Topology snapshot."))); + + Assert.IsInstanceOf<IgniteNLogLogger>(ignite.Logger); + + ignite.Logger.Info("Log from user code."); + + Assert.IsTrue(_logTarget.Logs.Contains("|Info|Log from user code.||")); + } + + Assert.IsTrue(_logTarget.Logs.Contains( + "org.apache.ignite.internal.IgniteKernal|Debug|Grid is stopping.||")); + } + + /// <summary> + /// Gets the last log. + /// </summary> + private string GetLastLog() + { + return _logTarget.Logs.Last(); + } + + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.csproj b/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.csproj new file mode 100644 index 0000000..c8d8705 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.csproj @@ -0,0 +1,74 @@ +<?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>{C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Apache.Ignite.NLog</RootNamespace> + <AssemblyName>Apache.Ignite.NLog</AssemblyName> + <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </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> + </PropertyGroup> + <PropertyGroup> + <SignAssembly>true</SignAssembly> + </PropertyGroup> + <PropertyGroup> + <AssemblyOriginatorKeyFile>Apache.Ignite.NLog.snk</AssemblyOriginatorKeyFile> + </PropertyGroup> + <ItemGroup> + <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> + <HintPath>..\packages\NLog.4.3.7\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.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="IgniteNLogLogger.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\Apache.Ignite.Core\Apache.Ignite.Core.csproj"> + <Project>{4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}</Project> + <Name>Apache.Ignite.Core</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup> + <None Include="Apache.Ignite.NLog.snk" /> + <None Include="Apache.Ignite.NLog.nuspec" /> + <None Include="packages.config" /> + </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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.nuspec ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.nuspec b/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.nuspec new file mode 100644 index 0000000..765e26f --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.nuspec @@ -0,0 +1,50 @@ +<?xml version="1.0"?> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- + +Creating NuGet package: +1) Build Apache.Ignite.sln (AnyCPU configuration) +2) Create package (use csproj instead of nuspec so that template substitution works): + nuget pack Apache.Ignite.NLog.csproj -Prop Configuration=Release -Prop Platform=AnyCPU + +--> + +<package > + <metadata> + <id>Apache.Ignite.NLog</id> + <title>Apache Ignite NLog Logger</title> + <!-- --> + <version>$version$</version> + <authors>Apache Ignite</authors> + <owners>Apache Software Foundation</owners> + <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl> + <projectUrl>https://ignite.apache.org/</projectUrl> + <iconUrl>https://ignite.apache.org/images/logo_ignite_32_32.png</iconUrl> + <requireLicenseAcceptance>false</requireLicenseAcceptance> + <description>NLog Logger for Apache Ignite</description> + <releaseNotes></releaseNotes> + <copyright>Copyright 2016</copyright> + <tags>Apache Ignite In-Memory Distributed Computing SQL NoSQL LINQ Grid Map Reduce Cache NLog logger</tags> + <dependencies> + <dependency id="Apache.Ignite" version="[$version$]" /> + <dependency id="NLog" version="[4.0.0, 5.0.0)" /> + </dependencies> + </metadata> +</package> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.snk ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.snk b/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.snk new file mode 100644 index 0000000..799e742 Binary files /dev/null and b/modules/platforms/dotnet/Apache.Ignite.NLog/Apache.Ignite.NLog.snk differ http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.NLog/IgniteNLogLogger.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.NLog/IgniteNLogLogger.cs b/modules/platforms/dotnet/Apache.Ignite.NLog/IgniteNLogLogger.cs new file mode 100644 index 0000000..2730e37 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.NLog/IgniteNLogLogger.cs @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.NLog +{ + using System; + using Apache.Ignite.Core.Impl.Common; + using global::NLog; + using ILogger = Apache.Ignite.Core.Log.ILogger; + using IgniteLogLevel = Apache.Ignite.Core.Log.LogLevel; + using NLogLogLevel = global::NLog.LogLevel; + + /// <summary> + /// Ignite NLog integration. + /// </summary> + public class IgniteNLogLogger : ILogger + { + /// <summary> + /// The NLog logger. + /// </summary> + private readonly Logger _logger; + + /// <summary> + /// Initializes a new instance of the <see cref="IgniteNLogLogger"/> class using the + /// <see cref="LogManager.GetCurrentClassLogger()"/> to retrieve the NLog logger. + /// </summary> + public IgniteNLogLogger() : this(LogManager.GetCurrentClassLogger()) + { + // No-op. + } + + /// <summary> + /// Initializes a new instance of the <see cref="IgniteNLogLogger"/> class. + /// </summary> + /// <param name="logger">The NLog logger instance.</param> + public IgniteNLogLogger(Logger logger) + { + IgniteArgumentCheck.NotNull(logger, "logger"); + + _logger = logger; + } + + /// <summary> + /// Logs the specified message. + /// </summary> + /// <param name="level">The level.</param> + /// <param name="message">The message.</param> + /// <param name="args">The arguments to format <paramref name="message" />. + /// Can be null (formatting will not occur).</param> + /// <param name="formatProvider">The format provider. Can be null if <paramref name="args" /> is null.</param> + /// <param name="category">The logging category name.</param> + /// <param name="nativeErrorInfo">The native error information.</param> + /// <param name="ex">The exception. Can be null.</param> + /// <exception cref="System.NotImplementedException"></exception> + public void Log(IgniteLogLevel level, string message, object[] args, IFormatProvider formatProvider, + string category, string nativeErrorInfo, Exception ex) + { + var logEvent = new LogEventInfo + { + Level = ConvertLogLevel(level), + Message = message, + FormatProvider = formatProvider, + Parameters = args, + Exception = ex, + LoggerName = category + }; + + if (nativeErrorInfo != null) + logEvent.Properties.Add("nativeErrorInfo", nativeErrorInfo); + + _logger.Log(logEvent); + } + + /// <summary> + /// Determines whether the specified log level is enabled. + /// </summary> + /// <param name="level">The level.</param> + /// <returns> + /// Value indicating whether the specified log level is enabled + /// </returns> + /// <exception cref="System.NotImplementedException"></exception> + public bool IsEnabled(IgniteLogLevel level) + { + return _logger.IsEnabled(ConvertLogLevel(level)); + } + + /// <summary> + /// Converts the Ignite LogLevel to the NLog log level. + /// </summary> + /// <param name="level">The Ignite log level.</param> + /// <returns>Corresponding NLog log level.</returns> + public static NLogLogLevel ConvertLogLevel(IgniteLogLevel level) + { + switch (level) + { + case IgniteLogLevel.Trace: + return NLogLogLevel.Trace; + case IgniteLogLevel.Debug: + return NLogLogLevel.Debug; + case IgniteLogLevel.Info: + return NLogLogLevel.Info; + case IgniteLogLevel.Warn: + return NLogLogLevel.Warn; + case IgniteLogLevel.Error: + return NLogLogLevel.Error; + default: + throw new ArgumentOutOfRangeException("level", level, "Invalid Ignite LogLevel."); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.NLog/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.NLog/Properties/AssemblyInfo.cs b/modules/platforms/dotnet/Apache.Ignite.NLog/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6603836 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.NLog/Properties/AssemblyInfo.cs @@ -0,0 +1,40 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Apache.Ignite.NLog")] +[assembly: AssemblyDescription("Apache Ignite.NET NLog integration.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Apache Software Foundation")] +[assembly: AssemblyProduct("Apache Ignite.NET")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c6b58e4a-a2e9-4554-ad02-68ce6da5cfb7")] + +[assembly: AssemblyVersion("1.8.0.13244")] +[assembly: AssemblyFileVersion("1.8.0.13244")] +[assembly: AssemblyInformationalVersion("1.8.0")] + +[assembly: CLSCompliant(true)] http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.NLog/packages.config ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.NLog/packages.config b/modules/platforms/dotnet/Apache.Ignite.NLog/packages.config new file mode 100644 index 0000000..50aeb52 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.NLog/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="NLog" version="4.3.7" targetFramework="net40" /> +</packages> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/1c82cd04/modules/platforms/dotnet/Apache.Ignite.sln ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.sln b/modules/platforms/dotnet/Apache.Ignite.sln index 8a3bf04..2978780 100644 --- a/modules/platforms/dotnet/Apache.Ignite.sln +++ b/modules/platforms/dotnet/Apache.Ignite.sln @@ -38,6 +38,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.AspNet", "Apa EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.AspNet.Tests", "Apache.Ignite.AspNet.Tests\Apache.Ignite.AspNet.Tests.csproj", "{18EA4C71-A11D-4AB1-8042-418F7559D84F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.NLog", "Apache.Ignite.NLog\Apache.Ignite.NLog.csproj", "{C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -188,6 +190,18 @@ Global {18EA4C71-A11D-4AB1-8042-418F7559D84F}.Release|x64.Build.0 = Release|Any CPU {18EA4C71-A11D-4AB1-8042-418F7559D84F}.Release|x86.ActiveCfg = Release|Any CPU {18EA4C71-A11D-4AB1-8042-418F7559D84F}.Release|x86.Build.0 = Release|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Debug|x64.ActiveCfg = Debug|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Debug|x64.Build.0 = Debug|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Debug|x86.ActiveCfg = Debug|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Debug|x86.Build.0 = Debug|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Release|Any CPU.Build.0 = Release|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Release|x64.ActiveCfg = Release|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Release|x64.Build.0 = Release|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Release|x86.ActiveCfg = Release|Any CPU + {C6B58E4A-A2E9-4554-AD02-68CE6DA5CFB7}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE
