Skip to content
This repository
Browse code

Added logging integrations, verified service behavior under control

  • Loading branch information...
commit 0c3f563444ef11bfb24fa69656c2a5eafe3c21ef 1 parent f70d297
Chris Patterson authored August 26, 2012

Showing 45 changed files with 1,193 additions and 441 deletions. Show diff stats Hide diff stats

  1. 2  .semver
  2. 62  rakefile.rb
  3. 6  src/.nuget/NuGet.Config
  4. 139  src/.nuget/NuGet.targets
  5. BIN  src/.nuget/nuget.exe
  6. 4  src/.nuget/packages.config
  7. 10  src/SampleTopshelfService/SampleService.cs
  8. 2  src/SolutionVersion.cs
  9. 54  src/Topshelf.Log4Net/Log4NetConfigurationExtensions.cs
  10. 264  src/Topshelf.Log4Net/Logging/Log4NetLogWriter.cs
  11. 48  src/Topshelf.Log4Net/Logging/Log4NetLogWriterFactory.cs
  12. 78  src/Topshelf.Log4Net/Topshelf.Log4Net.csproj
  13. 4  src/Topshelf.Log4Net/packages.config
  14. 255  src/Topshelf.NLog/Logging/NLogLogWriter.cs
  15. 47  src/Topshelf.NLog/Logging/NLogLogWriterFactory.cs
  16. 43  src/Topshelf.NLog/NLogConfiguratorExtensions.cs
  17. 77  src/Topshelf.NLog/Topshelf.NLog.csproj
  18. 4  src/Topshelf.NLog/packages.config
  19. 12  src/Topshelf.Tests/Topshelf.Tests.csproj
  20. 3  src/Topshelf.Tests/packages.config
  21. 30  src/Topshelf.sln
  22. 2  src/Topshelf/Configuration/Builders/RunBuilder.cs
  23. 4  src/Topshelf/Configuration/Configurators/ValidateConfigurationResult.cs
  24. 2  src/Topshelf/Configuration/HostConfigurators/HostConfiguratorImpl.cs
  25. 2  src/Topshelf/HostFactory.cs
  26. 4  src/Topshelf/Hosts/ConsoleRunHost.cs
  27. 2  src/Topshelf/Hosts/InstallHost.cs
  28. 2  src/Topshelf/Hosts/StartHost.cs
  29. 2  src/Topshelf/Hosts/StopHost.cs
  30. 2  src/Topshelf/Hosts/UninstallHost.cs
  31. 2  src/Topshelf/Internals
  32. 82  src/Topshelf/Logging/HostLogger.cs
  33. 22  src/Topshelf/Logging/{Log.cs → LogWriter.cs}
  34. 4  src/Topshelf/Logging/{ILogger.cs → LogWriterFactory.cs}
  35. 2  src/Topshelf/Logging/{LogOutputProvider.cs → LogWriterOutputProvider.cs}
  36. 143  src/Topshelf/Logging/Logger.cs
  37. 30  src/Topshelf/Logging/{LogLevel.cs → LoggingLevel.cs}
  38. 112  src/Topshelf/Logging/{TraceLog.cs → TraceLogWriter.cs}
  39. 18  src/Topshelf/Logging/{TraceLogger.cs → TraceLogWriterFactory.cs}
  40. 2  src/Topshelf/Runtime/Windows/HostInstaller.cs
  41. 4  src/Topshelf/Runtime/Windows/WindowsHostEnvironment.cs
  42. 2  src/Topshelf/Runtime/Windows/WindowsServiceControlManager.cs
  43. 29  src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
  44. 2  src/Topshelf/Runtime/Windows/WindowsUserAccessControl.cs
  45. 14  src/Topshelf/Topshelf.csproj
2  .semver
... ...
@@ -1,5 +1,5 @@
1 1
 --- 
2 2
 :patch: 0
3  
-:special: prerelease
  3
+:special: ""
4 4
 :major: 3
5 5
 :minor: 0
62  rakefile.rb
@@ -55,11 +55,15 @@
55 55
 task :compile => [:versioning, :global_version, :build4, :tests4, :copy4, :build35, :tests35, :copy35]
56 56
 
57 57
 task :copy35 => [:build35] do
58  
-	copyOutputFiles File.join(props[:src], "Topshelf/bin/Release/v3.5"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
  58
+  copyOutputFiles File.join(props[:src], "Topshelf/bin/Release/v3.5"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
  59
+  copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release/v3.5"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
  60
+	copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release/v3.5"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
59 61
 end
60 62
 
61 63
 task :copy4 => [:build4] do
62  
-	copyOutputFiles File.join(props[:src], "Topshelf/bin/Release"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
  64
+  copyOutputFiles File.join(props[:src], "Topshelf/bin/Release"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
  65
+  copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
  66
+	copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
63 67
 end
64 68
 
65 69
 desc "Only compiles the application."
@@ -90,14 +94,14 @@ def copyOutputFiles(fromDir, filePattern, outDir)
90 94
 
91 95
 desc "Runs unit tests"
92 96
 nunit :tests35 => [:build35] do |nunit|
93  
-          nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.0.12051', 'tools', 'nunit-console.exe')
  97
+          nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.1', 'tools', 'nunit-console.exe')
94 98
           nunit.options = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results-net-3.5.xml')}\""
95 99
           nunit.assemblies = FileList[File.join(props[:src], "Topshelf.Tests/bin/Release", "Topshelf.Tests.dll")]
96 100
 end
97 101
 
98 102
 desc "Runs unit tests"
99 103
 nunit :tests4 => [:build4] do |nunit|
100  
-          nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.0.12051', 'tools', 'nunit-console.exe')
  104
+          nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.1', 'tools', 'nunit-console.exe')
101 105
           nunit.options = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results-net-4.0.xml')}\""
102 106
           nunit.assemblies = FileList[File.join(props[:src], "Topshelf.Tests/bin/Release", "Topshelf.Tests.dll")]
103 107
 end
@@ -113,21 +117,23 @@ def copyOutputFiles(fromDir, filePattern, outDir)
113 117
 
114 118
 desc "Restore NuGet Packages"
115 119
 task :nuget_restore do
  120
+  sh "#{File.join(props[:lib], 'nuget.exe')} install #{File.join(props[:src],"Topshelf.Log4Net","packages.config")} -Source https://nuget.org/api/v2/ -o #{File.join(props[:src],"packages")}"
  121
+  sh "#{File.join(props[:lib], 'nuget.exe')} install #{File.join(props[:src],"Topshelf.NLog","packages.config")} -Source https://nuget.org/api/v2/ -o #{File.join(props[:src],"packages")}"
116 122
   sh "#{File.join(props[:lib], 'nuget.exe')} install #{File.join(props[:src],"Topshelf.Tests","packages.config")} -Source https://nuget.org/api/v2/ -o #{File.join(props[:src],"packages")}"
117  
-  sh "#{File.join(props[:lib], 'nuget.exe')} install #{File.join(props[:src],".nuget","packages.config")} -Source https://nuget.org/api/v2/ -o #{File.join(props[:src],"packages")}"
118 123
 end
119 124
 
120 125
 desc "Builds the nuget package"
121 126
 task :nuget => [:versioning, :create_nuspec] do
122  
-	sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
  127
+  sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
  128
+  sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.Log4Net.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
  129
+	sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.NLog.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
123 130
 end
124 131
 
125  
-task :create_nuspec => [:main_nuspec]
126  
-
127  
-nuspec :main_nuspec do |nuspec|
  132
+nuspec :create_nuspec do |nuspec|
128 133
   nuspec.id = 'Topshelf'
129 134
   nuspec.version = NUGET_VERSION
130 135
   nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
  136
+  nuspec.summary = 'Topshelf, Friction-free Windows Services'
131 137
   nuspec.description = 'Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
132 138
   nuspec.title = 'Topshelf'
133 139
   nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
@@ -140,6 +146,44 @@ def copyOutputFiles(fromDir, filePattern, outDir)
140 146
   nuspec.file(File.join(props[:src], "Topshelf\\**\\*.cs").gsub("/","\\"), "src")
141 147
 end
142 148
 
  149
+nuspec :create_nuspec do |nuspec|
  150
+  nuspec.id = 'Topshelf.Log4Net'
  151
+  nuspec.version = NUGET_VERSION
  152
+  nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
  153
+  nuspec.summary = 'Topshelf, Friction-free Windows Services'
  154
+  nuspec.description = 'Log4Net Logging Integration for Topshelf. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
  155
+  nuspec.title = 'Topshelf.Log4Net'
  156
+  nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
  157
+  nuspec.iconUrl = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
  158
+  nuspec.language = "en-US"
  159
+  nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
  160
+  nuspec.requireLicenseAcceptance = "false"
  161
+  nuspec.dependency "Topshelf", NUGET_VERSION
  162
+  nuspec.dependency "Log4Net", "2.0.0"
  163
+  nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Log4Net.nuspec')
  164
+  add_files props[:output], 'Topshelf.Log4Net.{dll,pdb,xml}', nuspec
  165
+  nuspec.file(File.join(props[:src], "Topshelf.Log4Net\\**\\*.cs").gsub("/","\\"), "src")
  166
+end
  167
+
  168
+nuspec :create_nuspec do |nuspec|
  169
+  nuspec.id = 'Topshelf.NLog'
  170
+  nuspec.version = NUGET_VERSION
  171
+  nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
  172
+  nuspec.summary = 'Topshelf, Friction-free Windows Services'
  173
+  nuspec.description = 'NLog Logging Integration for Topshelf. Topshelf is an open source project for hosting services without friction. By referencing Topshelf, your console application *becomes* a service installer with a comprehensive set of command-line options for installing, configuring, and running your application as a service.'
  174
+  nuspec.title = 'Topshelf.NLog'
  175
+  nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
  176
+  nuspec.iconUrl = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
  177
+  nuspec.language = "en-US"
  178
+  nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
  179
+  nuspec.requireLicenseAcceptance = "false"
  180
+  nuspec.dependency "Topshelf", NUGET_VERSION
  181
+  nuspec.dependency "NLog", "2.0"
  182
+  nuspec.output_file = File.join(props[:artifacts], 'Topshelf.NLog.nuspec')
  183
+  add_files props[:output], 'Topshelf.NLog.{dll,pdb,xml}', nuspec
  184
+  nuspec.file(File.join(props[:src], "Topshelf.NLog\\**\\*.cs").gsub("/","\\"), "src")
  185
+end
  186
+
143 187
 def project_outputs(props)
144 188
 	props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
145 189
 		concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
6  src/.nuget/NuGet.Config
... ...
@@ -1,6 +0,0 @@
1  
-<?xml version="1.0" encoding="utf-8"?>
2  
-<configuration>
3  
-  <solution>
4  
-    <add key="disableSourceControlIntegration" value="true" />
5  
-  </solution>
6  
-</configuration>
139  src/.nuget/NuGet.targets
... ...
@@ -1,139 +0,0 @@
1  
-<?xml version="1.0" encoding="utf-8"?>
2  
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3  
-    <PropertyGroup>
4  
-        <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5  
-        
6  
-        <!-- Enable the restore command to run before builds -->
7  
-        <RestorePackages Condition="  '$(RestorePackages)' == '' ">false</RestorePackages>
8  
-
9  
-        <!-- Property that enables building a package from a project -->
10  
-        <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11  
-        
12  
-        <!-- Download NuGet.exe if it does not already exist -->
13  
-        <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
14  
-    </PropertyGroup>
15  
-    
16  
-    <ItemGroup Condition=" '$(PackageSources)' == '' ">
17  
-        <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
18  
-        <!--
19  
-            <PackageSource Include="https://nuget.org/api/v2/" />
20  
-            <PackageSource Include="https://my-nuget-source/nuget/" />
21  
-        -->
22  
-    </ItemGroup>
23  
-
24  
-    <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
25  
-        <!-- Windows specific commands -->
26  
-        <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
27  
-        <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
28  
-        <PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
29  
-    </PropertyGroup>
30  
-    
31  
-    <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
32  
-        <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
33  
-        <NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
34  
-        <PackagesConfig>packages.config</PackagesConfig>
35  
-        <PackagesDir>$(SolutionDir)packages</PackagesDir>
36  
-    </PropertyGroup>
37  
-    
38  
-    <PropertyGroup>
39  
-        <!-- NuGet command -->
40  
-        <NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
41  
-        <PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
42  
-        
43  
-        <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
44  
-        <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
45  
-
46  
-        <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
47  
-
48  
-        <!-- Commands -->
49  
-        <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" -o "$(PackagesDir)"</RestoreCommand>
50  
-        <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
51  
-
52  
-        <!-- Make the build depend on restore packages -->
53  
-        <BuildDependsOn Condition="$(RestorePackages) == 'true'">
54  
-            RestorePackages;
55  
-            $(BuildDependsOn);
56  
-        </BuildDependsOn>
57  
-
58  
-        <!-- Make the build depend on restore packages -->
59  
-        <BuildDependsOn Condition="$(BuildPackage) == 'true'">
60  
-            $(BuildDependsOn);
61  
-            BuildPackage;
62  
-        </BuildDependsOn>
63  
-    </PropertyGroup>
64  
-
65  
-    <Target Name="CheckPrerequisites">
66  
-        <!-- Raise an error if we're unable to locate nuget.exe  -->
67  
-        <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
68  
-        <SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
69  
-        <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')"  />
70  
-    </Target>
71  
-
72  
-    <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
73  
-        <Exec Command="$(RestoreCommand)"
74  
-              Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
75  
-              
76  
-        <Exec Command="$(RestoreCommand)"
77  
-              LogStandardErrorAsError="true"
78  
-              Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
79  
-    </Target>
80  
-
81  
-    <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
82  
-        <Exec Command="$(BuildCommand)" 
83  
-              Condition=" '$(OS)' != 'Windows_NT' " />
84  
-              
85  
-        <Exec Command="$(BuildCommand)"
86  
-              LogStandardErrorAsError="true"
87  
-              Condition=" '$(OS)' == 'Windows_NT' " />
88  
-    </Target>
89  
-    
90  
-    <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
91  
-        <ParameterGroup>
92  
-            <OutputFilename ParameterType="System.String" Required="true" />
93  
-        </ParameterGroup>
94  
-        <Task>
95  
-            <Reference Include="System.Core" />
96  
-            <Using Namespace="System" />
97  
-            <Using Namespace="System.IO" />
98  
-            <Using Namespace="System.Net" />
99  
-            <Using Namespace="Microsoft.Build.Framework" />
100  
-            <Using Namespace="Microsoft.Build.Utilities" />
101  
-            <Code Type="Fragment" Language="cs">
102  
-                <![CDATA[
103  
-                try {
104  
-                    OutputFilename = Path.GetFullPath(OutputFilename);
105  
-
106  
-                    Log.LogMessage("Downloading latest version of NuGet.exe...");
107  
-                    WebClient webClient = new WebClient();
108  
-                    webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
109  
-
110  
-                    return true;
111  
-                }
112  
-                catch (Exception ex) {
113  
-                    Log.LogErrorFromException(ex);
114  
-                    return false;
115  
-                }
116  
-            ]]>
117  
-            </Code>
118  
-        </Task>
119  
-    </UsingTask>
120  
-    
121  
-     <UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
122  
-        <ParameterGroup>
123  
-            <EnvKey ParameterType="System.String" Required="true" />
124  
-            <EnvValue ParameterType="System.String" Required="true" />
125  
-        </ParameterGroup>
126  
-        <Task>
127  
-            <Using Namespace="System" />
128  
-            <Code Type="Fragment" Language="cs">
129  
-                <![CDATA[
130  
-                try {
131  
-                    Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
132  
-                }
133  
-                catch  {
134  
-                }
135  
-            ]]>
136  
-            </Code>
137  
-        </Task>
138  
-    </UsingTask>
139  
-</Project>
BIN  src/.nuget/nuget.exe
Binary file not shown
4  src/.nuget/packages.config
... ...
@@ -1,4 +0,0 @@
1  
-<?xml version="1.0" encoding="utf-8"?>
2  
-<packages>
3  
-  <package id="NUnit.Runners" version="2.6.0.12051" />
4  
-</packages>
10  src/SampleTopshelfService/SampleService.cs
@@ -20,7 +20,7 @@ namespace SampleTopshelfService
20 20
     class SampleService :
21 21
         ServiceControl
22 22
     {
23  
-        static readonly Log _log = Logger.Get<SampleService>();
  23
+        static readonly LogWriter _log = HostLogger.Get<SampleService>();
24 24
 
25 25
         public bool Start(HostControl hostControl)
26 26
         {
@@ -30,6 +30,14 @@ public bool Start(HostControl hostControl)
30 30
 
31 31
             Thread.Sleep(1000);
32 32
 
  33
+            ThreadPool.QueueUserWorkItem(x =>
  34
+                {
  35
+                    Thread.Sleep(3000);
  36
+
  37
+                    _log.Info("Requesting stop");
  38
+
  39
+                    hostControl.Stop();
  40
+                });
33 41
             _log.Info("SampleService Started");
34 42
 
35 43
             return true;
2  src/SolutionVersion.cs
@@ -9,5 +9,5 @@
9 9
 
10 10
 [assembly: ComVisibleAttribute(false)]
11 11
 [assembly: CLSCompliantAttribute(true)]
12  
-[assembly: AssemblyInformationalVersion("3.0.0-prerelease.251b83")]
  12
+[assembly: AssemblyInformationalVersion("3.0.0.f70d29")]
13 13
 
54  src/Topshelf.Log4Net/Log4NetConfigurationExtensions.cs
... ...
@@ -0,0 +1,54 @@
  1
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
  2
+//  
  3
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
  4
+// this file except in compliance with the License. You may obtain a copy of the 
  5
+// License at 
  6
+// 
  7
+//     http://www.apache.org/licenses/LICENSE-2.0 
  8
+// 
  9
+// Unless required by applicable law or agreed to in writing, software distributed 
  10
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
  11
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  12
+// specific language governing permissions and limitations under the License.
  13
+namespace Topshelf
  14
+{
  15
+    using System;
  16
+    using System.IO;
  17
+    using HostConfigurators;
  18
+    using Logging;
  19
+
  20
+    /// <summary>
  21
+    ///   Extensions for configuring Logging for log4net
  22
+    /// </summary>
  23
+    public static class Log4NetConfigurationExtensions
  24
+    {
  25
+        /// <summary>
  26
+        ///   Specify that you want to use the Log4net logging engine.
  27
+        /// </summary>
  28
+        /// <param name="configurator"> </param>
  29
+        public static void UseLog4Net(this HostConfigurator configurator)
  30
+        {
  31
+            Log4NetLogWriterFactory.Use();
  32
+        }
  33
+
  34
+        /// <summary>
  35
+        ///   Specify that you want to use the Log4net logging engine.
  36
+        /// </summary>
  37
+        /// <param name="configurator"> </param>
  38
+        /// <param name="configFileName"> The name of the log4net xml configuration file </param>
  39
+        public static void UseLog4Net(this HostConfigurator configurator, string configFileName)
  40
+        {
  41
+            Log4NetLogWriterFactory.Use();
  42
+
  43
+            string path = AppDomain.CurrentDomain.BaseDirectory;
  44
+
  45
+            string file = Path.Combine(path, configFileName);
  46
+
  47
+            var configFile = new FileInfo(file);
  48
+            if (configFile.Exists)
  49
+            {
  50
+                Log4NetLogWriterFactory.Use(file);
  51
+            }
  52
+        }
  53
+    }
  54
+}
264  src/Topshelf.Log4Net/Logging/Log4NetLogWriter.cs
... ...
@@ -0,0 +1,264 @@
  1
+// Copyright 2007-2011 Chris Patterson, Dru Sellers, Travis Smith, et. al.
  2
+//  
  3
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
  4
+// this file except in compliance with the License. You may obtain a copy of the 
  5
+// License at 
  6
+// 
  7
+//     http://www.apache.org/licenses/LICENSE-2.0 
  8
+// 
  9
+// Unless required by applicable law or agreed to in writing, software distributed 
  10
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
  11
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  12
+// specific language governing permissions and limitations under the License.
  13
+namespace Topshelf.Logging
  14
+{
  15
+    using System;
  16
+    using System.Globalization;
  17
+    using Topshelf.Logging;
  18
+
  19
+    public class Log4NetLogWriter :
  20
+        LogWriter
  21
+    {
  22
+        readonly log4net.ILog _log;
  23
+
  24
+        public Log4NetLogWriter(log4net.ILog log)
  25
+        {
  26
+            _log = log;
  27
+        }
  28
+
  29
+        public void Debug(object message)
  30
+        {
  31
+            _log.Debug(message);
  32
+        }
  33
+
  34
+        public void Debug(object message, Exception exception)
  35
+        {
  36
+            _log.Debug(message, exception);
  37
+        }
  38
+
  39
+        public void Debug(LogWriterOutputProvider messageProvider)
  40
+        {
  41
+            if (!IsDebugEnabled)
  42
+                return;
  43
+
  44
+            _log.Debug(messageProvider());
  45
+        }
  46
+
  47
+        public void DebugFormat(string format, params object[] args)
  48
+        {
  49
+            _log.DebugFormat(format, args);
  50
+        }
  51
+
  52
+        public void DebugFormat(IFormatProvider provider, string format, params object[] args)
  53
+        {
  54
+            _log.DebugFormat(provider, format, args);
  55
+        }
  56
+
  57
+        public void Info(object message)
  58
+        {
  59
+            _log.Info(message);
  60
+        }
  61
+
  62
+        public void Info(object message, Exception exception)
  63
+        {
  64
+            _log.Info(message, exception);
  65
+        }
  66
+
  67
+        public void Info(LogWriterOutputProvider messageProvider)
  68
+        {
  69
+            if (!IsInfoEnabled)
  70
+                return;
  71
+
  72
+            _log.Info(messageProvider());
  73
+        }
  74
+
  75
+        public void InfoFormat(string format, params object[] args)
  76
+        {
  77
+            _log.InfoFormat(format, args);
  78
+        }
  79
+
  80
+        public void InfoFormat(IFormatProvider provider, string format, params object[] args)
  81
+        {
  82
+            _log.InfoFormat(provider, format, args);
  83
+        }
  84
+
  85
+        public void Warn(object message)
  86
+        {
  87
+            _log.Warn(message);
  88
+        }
  89
+
  90
+        public void Warn(object message, Exception exception)
  91
+        {
  92
+            _log.Warn(message, exception);
  93
+        }
  94
+
  95
+        public void Warn(LogWriterOutputProvider messageProvider)
  96
+        {
  97
+            if (!IsWarnEnabled)
  98
+                return;
  99
+
  100
+            _log.Warn(messageProvider());
  101
+        }
  102
+
  103
+        public void WarnFormat(string format, params object[] args)
  104
+        {
  105
+            _log.WarnFormat(format, args);
  106
+        }
  107
+
  108
+        public void WarnFormat(IFormatProvider provider, string format, params object[] args)
  109
+        {
  110
+            _log.WarnFormat(provider, format, args);
  111
+        }
  112
+
  113
+        public void Error(object message)
  114
+        {
  115
+            _log.Error(message);
  116
+        }
  117
+
  118
+        public void Error(object message, Exception exception)
  119
+        {
  120
+            _log.Error(message, exception);
  121
+        }
  122
+
  123
+        public void Error(LogWriterOutputProvider messageProvider)
  124
+        {
  125
+            if (!IsErrorEnabled)
  126
+                return;
  127
+
  128
+            _log.Error(messageProvider());
  129
+        }
  130
+
  131
+        public void ErrorFormat(string format, params object[] args)
  132
+        {
  133
+            _log.ErrorFormat(format, args);
  134
+        }
  135
+
  136
+        public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
  137
+        {
  138
+            _log.ErrorFormat(provider, format, args);
  139
+        }
  140
+
  141
+        public void Fatal(object message)
  142
+        {
  143
+            _log.Fatal(message);
  144
+        }
  145
+
  146
+        public void Fatal(object message, Exception exception)
  147
+        {
  148
+            _log.Fatal(message, exception);
  149
+        }
  150
+
  151
+        public void Fatal(LogWriterOutputProvider messageProvider)
  152
+        {
  153
+            if (!IsFatalEnabled)
  154
+                return;
  155
+
  156
+            _log.Fatal(messageProvider());
  157
+        }
  158
+
  159
+        public void FatalFormat(string format, params object[] args)
  160
+        {
  161
+            _log.FatalFormat(format, args);
  162
+        }
  163
+
  164
+        public void FatalFormat(IFormatProvider provider, string format, params object[] args)
  165
+        {
  166
+            _log.FatalFormat(provider, format, args);
  167
+        }
  168
+
  169
+        public bool IsDebugEnabled
  170
+        {
  171
+            get { return _log.IsDebugEnabled; }
  172
+        }
  173
+
  174
+        public bool IsInfoEnabled
  175
+        {
  176
+            get { return _log.IsInfoEnabled; }
  177
+        }
  178
+
  179
+        public bool IsWarnEnabled
  180
+        {
  181
+            get { return _log.IsWarnEnabled; }
  182
+        }
  183
+
  184
+        public bool IsErrorEnabled
  185
+        {
  186
+            get { return _log.IsErrorEnabled; }
  187
+        }
  188
+
  189
+        public bool IsFatalEnabled
  190
+        {
  191
+            get { return _log.IsFatalEnabled; }
  192
+        }
  193
+
  194
+        public void Log(LoggingLevel level, object obj)
  195
+        {
  196
+            if (level == LoggingLevel.Fatal)
  197
+                Fatal(obj);
  198
+            else if (level == LoggingLevel.Error)
  199
+                Error(obj);
  200
+            else if (level == LoggingLevel.Warn)
  201
+                Warn(obj);
  202
+            else if (level == LoggingLevel.Info)
  203
+                Info(obj);
  204
+            else if (level >= LoggingLevel.Debug)
  205
+                Debug(obj);
  206
+        }
  207
+
  208
+        public void Log(LoggingLevel level, object obj, Exception exception)
  209
+        {
  210
+            if (level == LoggingLevel.Fatal)
  211
+                Fatal(obj, exception);
  212
+            else if (level == LoggingLevel.Error)
  213
+                Error(obj, exception);
  214
+            else if (level == LoggingLevel.Warn)
  215
+                Warn(obj, exception);
  216
+            else if (level == LoggingLevel.Info)
  217
+                Info(obj, exception);
  218
+            else if (level >= LoggingLevel.Debug)
  219
+                Debug(obj, exception);
  220
+        }
  221
+
  222
+        public void Log(LoggingLevel level, LogWriterOutputProvider messageProvider)
  223
+        {
  224
+            if (level == LoggingLevel.Fatal)
  225
+                Fatal(messageProvider);
  226
+            else if (level == LoggingLevel.Error)
  227
+                Error(messageProvider);
  228
+            else if (level == LoggingLevel.Warn)
  229
+                Warn(messageProvider);
  230
+            else if (level == LoggingLevel.Info)
  231
+                Info(messageProvider);
  232
+            else if (level >= LoggingLevel.Debug)
  233
+                Debug(messageProvider);
  234
+        }
  235
+
  236
+        public void LogFormat(LoggingLevel level, string format, params object[] args)
  237
+        {
  238
+            if (level == LoggingLevel.Fatal)
  239
+                FatalFormat(CultureInfo.InvariantCulture, format, args);
  240
+            else if (level == LoggingLevel.Error)
  241
+                ErrorFormat(CultureInfo.InvariantCulture, format, args);
  242
+            else if (level == LoggingLevel.Warn)
  243
+                WarnFormat(CultureInfo.InvariantCulture, format, args);
  244
+            else if (level == LoggingLevel.Info)
  245
+                InfoFormat(CultureInfo.InvariantCulture, format, args);
  246
+            else if (level >= LoggingLevel.Debug)
  247
+                DebugFormat(CultureInfo.InvariantCulture, format, args);
  248
+        }
  249
+
  250
+        public void LogFormat(LoggingLevel level, IFormatProvider formatProvider, string format, params object[] args)
  251
+        {
  252
+            if (level == LoggingLevel.Fatal)
  253
+                FatalFormat(formatProvider, format, args);
  254
+            else if (level == LoggingLevel.Error)
  255
+                ErrorFormat(formatProvider, format, args);
  256
+            else if (level == LoggingLevel.Warn)
  257
+                WarnFormat(formatProvider, format, args);
  258
+            else if (level == LoggingLevel.Info)
  259
+                InfoFormat(formatProvider, format, args);
  260
+            else if (level >= LoggingLevel.Debug)
  261
+                DebugFormat(formatProvider, format, args);
  262
+        }
  263
+    }
  264
+}
48  src/Topshelf.Log4Net/Logging/Log4NetLogWriterFactory.cs
... ...
@@ -0,0 +1,48 @@
  1
+// Copyright 2007-2011 Chris Patterson, Dru Sellers, Travis Smith, et. al.
  2
+//  
  3
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
  4
+// this file except in compliance with the License. You may obtain a copy of the 
  5
+// License at 
  6
+// 
  7
+//     http://www.apache.org/licenses/LICENSE-2.0 
  8
+// 
  9
+// Unless required by applicable law or agreed to in writing, software distributed 
  10
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
  11
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  12
+// specific language governing permissions and limitations under the License.
  13
+namespace Topshelf.Logging
  14
+{
  15
+    using System;
  16
+    using System.IO;
  17
+    using Topshelf.Logging;
  18
+    using log4net;
  19
+    using log4net.Config;
  20
+
  21
+    public class Log4NetLogWriterFactory :
  22
+        LogWriterFactory
  23
+    {
  24
+        public LogWriter Get(string name)
  25
+        {
  26
+            return new Log4NetLogWriter(LogManager.GetLogger(name));
  27
+        }
  28
+
  29
+        public void Shutdown()
  30
+        {
  31
+            LogManager.Shutdown();
  32
+        }
  33
+
  34
+        public static void Use()
  35
+        {
  36
+            HostLogger.UseLogger(new Log4NetLogWriterFactory());
  37
+        }
  38
+
  39
+        public static void Use(string file)
  40
+        {
  41
+            HostLogger.UseLogger(new Log4NetLogWriterFactory());
  42
+
  43
+            file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
  44
+            var configFile = new FileInfo(file);
  45
+            XmlConfigurator.Configure(configFile);
  46
+        }
  47
+    }
  48
+}
78  src/Topshelf.Log4Net/Topshelf.Log4Net.csproj
... ...
@@ -0,0 +1,78 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3
+  <PropertyGroup>
  4
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  5
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
  6
+    <ProductVersion>8.0.30703</ProductVersion>
  7
+    <SchemaVersion>2.0</SchemaVersion>
  8
+    <ProjectGuid>{0EE64D46-5728-45DB-8D0E-044CE2677FD8}</ProjectGuid>
  9
+    <OutputType>Library</OutputType>
  10
+    <AppDesignerFolder>Properties</AppDesignerFolder>
  11
+    <RootNamespace>Topshelf.Log4Net</RootNamespace>
  12
+    <AssemblyName>Topshelf.Log4Net</AssemblyName>
  13
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
  14
+    <FileAlignment>512</FileAlignment>
  15
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
  16
+    <RestorePackages>true</RestorePackages>
  17
+  </PropertyGroup>
  18
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  19
+    <DebugSymbols>true</DebugSymbols>
  20
+    <DebugType>full</DebugType>
  21
+    <Optimize>false</Optimize>
  22
+    <OutputPath>bin\Debug\</OutputPath>
  23
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
  24
+    <ErrorReport>prompt</ErrorReport>
  25
+    <WarningLevel>4</WarningLevel>
  26
+  </PropertyGroup>
  27
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  28
+    <DebugType>pdbonly</DebugType>
  29
+    <Optimize>true</Optimize>
  30
+    <OutputPath>bin\Release\</OutputPath>
  31
+    <DefineConstants>TRACE</DefineConstants>
  32
+    <ErrorReport>prompt</ErrorReport>
  33
+    <WarningLevel>4</WarningLevel>
  34
+  </PropertyGroup>
  35
+   <PropertyGroup Condition="  '$(TargetFrameworkVersion)' == 'v3.5' ">
  36
+    <DefineConstants>NET35</DefineConstants>
  37
+    <OutputPath>bin\$(Configuration)\$(TargetFrameworkVersion)</OutputPath>
  38
+  </PropertyGroup>
  39
+ <ItemGroup>
  40
+    <Reference Include="log4net" Condition="'$(TargetFrameworkVersion)' == 'v3.5'">
  41
+      <HintPath>..\packages\log4net.2.0.0\lib\net35-full\log4net.dll</HintPath>
  42
+    </Reference>
  43
+    <Reference Include="log4net" Condition="'$(TargetFrameworkVersion)' != 'v3.5'">
  44
+      <HintPath>..\packages\log4net.2.0.0\lib\net40-full\log4net.dll</HintPath>
  45
+    </Reference>
  46
+    <Reference Include="System" />
  47
+    <Reference Include="System.Core" />
  48
+    <Reference Include="System.Xml" />
  49
+  </ItemGroup>
  50
+  <ItemGroup>
  51
+    <Compile Include="..\SolutionVersion.cs">
  52
+      <Link>SolutionVersion.cs</Link>
  53
+    </Compile>
  54
+    <Compile Include="Log4NetConfigurationExtensions.cs" />
  55
+    <Compile Include="Logging\Log4NetLogWriter.cs" />
  56
+    <Compile Include="Logging\Log4NetLogWriterFactory.cs" />
  57
+  </ItemGroup>
  58
+  <ItemGroup>
  59
+    <ProjectReference Include="..\Topshelf\Topshelf.csproj">
  60
+      <Project>{A52AD64D-6455-4A22-8CCF-581851086578}</Project>
  61
+      <Name>Topshelf</Name>
  62
+    </ProjectReference>
  63
+  </ItemGroup>
  64
+  <ItemGroup>
  65
+    <None Include="packages.config" />
  66
+  </ItemGroup>
  67
+  <ItemGroup>
  68
+    <Folder Include="Properties\" />
  69
+  </ItemGroup>
  70
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  71
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
  72
+       Other similar extension points exist, see Microsoft.Common.targets.
  73
+  <Target Name="BeforeBuild">
  74
+  </Target>
  75
+  <Target Name="AfterBuild">
  76
+  </Target>
  77
+  -->
  78
+</Project>
4  src/Topshelf.Log4Net/packages.config
... ...
@@ -0,0 +1,4 @@
  1
+<?xml version="1.0" encoding="utf-8"?>
  2
+<packages>
  3
+  <package id="log4net" version="2.0.0" targetFramework="net40" />
  4
+</packages>
255  src/Topshelf.NLog/Logging/NLogLogWriter.cs
... ...
@@ -0,0 +1,255 @@
  1
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
  2
+//  
  3
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
  4
+// this file except in compliance with the License. You may obtain a copy of the 
  5
+// License at 
  6
+// 
  7
+//     http://www.apache.org/licenses/LICENSE-2.0 
  8
+// 
  9
+// Unless required by applicable law or agreed to in writing, software distributed 
  10
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
  11
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  12
+// specific language governing permissions and limitations under the License.
  13
+namespace Topshelf.Logging
  14
+{
  15
+    using System;
  16
+    using NLog;
  17
+
  18
+    /// <summary>
  19
+    ///   A logger that wraps to NLog. See http://stackoverflow.com/questions/7412156/how-to-retain-callsite-information-when-wrapping-nlog
  20
+    /// </summary>
  21
+    public class NLogLogWriter :
  22
+        LogWriter
  23
+    {
  24
+        readonly Logger _log;
  25
+
  26
+        /// <summary>
  27
+        ///   Create a new NLog logger instance.
  28
+        /// </summary>
  29
+        /// <param name="log"> </param>
  30
+        /// <param name="name"> Name of type to log as. </param>
  31
+        public NLogLogWriter(Logger log, string name)
  32
+        {
  33
+            if (name == null)
  34
+                throw new ArgumentNullException("name");
  35
+            _log = log;
  36
+        }
  37
+
  38
+        public bool IsDebugEnabled
  39
+        {
  40
+            get { return _log.IsDebugEnabled; }
  41
+        }
  42
+
  43
+        public bool IsInfoEnabled
  44
+        {
  45
+            get { return _log.IsInfoEnabled; }
  46
+        }
  47
+
  48
+        public bool IsWarnEnabled
  49
+        {
  50
+            get { return _log.IsWarnEnabled; }
  51
+        }
  52
+
  53
+        public bool IsErrorEnabled
  54
+        {
  55
+            get { return _log.IsErrorEnabled; }
  56
+        }
  57
+
  58
+        public bool IsFatalEnabled
  59
+        {
  60
+            get { return _log.IsFatalEnabled; }
  61
+        }
  62
+
  63
+        public void Log(LoggingLevel level, object obj)
  64
+        {
  65
+            _log.Log(GetNLogLevel(level), obj);
  66
+        }
  67
+
  68
+        public void Log(LoggingLevel level, object obj, Exception exception)
  69
+        {
  70
+            _log.LogException(GetNLogLevel(level), obj == null
  71
+                                                       ? ""
  72
+                                                       : obj.ToString(), exception);
  73
+        }
  74
+
  75
+        public void Log(LoggingLevel level, LogWriterOutputProvider messageProvider)
  76
+        {
  77
+            _log.Log(GetNLogLevel(level), ToGenerator(messageProvider));
  78
+        }
  79
+
  80
+        public void LogFormat(LoggingLevel level, IFormatProvider formatProvider, string format,
  81
+            params object[] args)
  82
+        {
  83
+            _log.Log(GetNLogLevel(level), formatProvider, format, args);
  84
+        }
  85
+
  86
+        public void LogFormat(LoggingLevel level, string format, params object[] args)
  87
+        {
  88
+            _log.Log(GetNLogLevel(level), format, args);
  89
+        }
  90
+
  91
+        public void Debug(object obj)
  92
+        {
  93
+            _log.Log(LogLevel.Debug, obj);
  94
+        }
  95
+
  96
+        public void Debug(object obj, Exception exception)
  97
+        {
  98
+            _log.LogException(LogLevel.Debug, obj == null
  99
+                                                       ? ""
  100
+                                                       : obj.ToString(), exception);
  101
+        }
  102
+
  103
+        public void Debug(LogWriterOutputProvider messageProvider)
  104
+        {
  105
+            _log.Debug(ToGenerator(messageProvider));
  106
+        }
  107
+
  108
+        public void Info(object obj)
  109
+        {
  110
+            _log.Log(LogLevel.Info, obj);
  111
+        }
  112
+
  113
+        public void Info(object obj, Exception exception)
  114
+        {
  115
+            _log.LogException(LogLevel.Info, obj == null
  116
+                                                      ? ""
  117
+                                                      : obj.ToString(), exception);
  118
+        }
  119
+
  120
+        public void Info(LogWriterOutputProvider messageProvider)
  121
+        {
  122
+            _log.Info(ToGenerator(messageProvider));
  123
+        }
  124
+
  125
+        public void Warn(object obj)
  126
+        {
  127
+            _log.Log(LogLevel.Warn, obj);
  128
+        }
  129
+
  130
+        public void Warn(object obj, Exception exception)
  131
+        {
  132
+            _log.LogException(LogLevel.Warn, obj == null
  133
+                                                      ? ""
  134
+                                                      : obj.ToString(), exception);
  135
+        }
  136
+
  137
+        public void Warn(LogWriterOutputProvider messageProvider)
  138
+        {
  139
+            _log.Warn(ToGenerator(messageProvider));
  140
+        }
  141
+
  142
+        public void Error(object obj)
  143
+        {
  144
+            _log.Log(LogLevel.Error, obj);
  145
+        }
  146
+
  147
+        public void Error(object obj, Exception exception)
  148
+        {
  149
+            _log.LogException(LogLevel.Error, obj == null
  150
+                                                       ? ""
  151
+                                                       : obj.ToString(), exception);
  152
+        }
  153
+
  154
+        public void Error(LogWriterOutputProvider messageProvider)
  155
+        {
  156
+            _log.Error(ToGenerator(messageProvider));
  157
+        }
  158
+
  159
+        public void Fatal(object obj)
  160
+        {
  161
+            _log.Log(LogLevel.Fatal, obj);
  162
+        }
  163
+
  164
+        public void Fatal(object obj, Exception exception)
  165
+        {
  166
+            _log.LogException(LogLevel.Fatal, obj == null
  167
+                                                       ? ""
  168
+                                                       : obj.ToString(), exception);
  169
+        }
  170
+
  171
+        public void Fatal(LogWriterOutputProvider messageProvider)
  172
+        {
  173
+            _log.Fatal(ToGenerator(messageProvider));
  174
+        }
  175
+
  176
+        public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args)
  177
+        {
  178
+            _log.Log(LogLevel.Debug, formatProvider, format, args);
  179
+        }
  180
+
  181
+        public void DebugFormat(string format, params object[] args)
  182
+        {
  183
+            _log.Log(LogLevel.Debug, format, args);
  184
+        }
  185
+
  186
+        public void InfoFormat(IFormatProvider formatProvider, string format, params object[] args)
  187
+        {
  188
+            _log.Log(LogLevel.Info, formatProvider, format, args);
  189
+        }
  190
+
  191
+        public void InfoFormat(string format, params object[] args)
  192
+        {
  193
+            _log.Log(LogLevel.Info, format, args);
  194
+        }
  195
+
  196
+        public void WarnFormat(IFormatProvider formatProvider, string format, params object[] args)
  197
+        {
  198
+            _log.Log(LogLevel.Warn, formatProvider, format, args);
  199
+        }
  200
+
  201
+        public void WarnFormat(string format, params object[] args)
  202
+        {
  203
+            _log.Log(LogLevel.Warn, format, args);
  204
+        }
  205
+
  206
+        public void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args)
  207
+        {
  208
+            _log.Log(LogLevel.Error, formatProvider, format, args);
  209
+        }
  210
+
  211
+        public void ErrorFormat(string format, params object[] args)
  212
+        {
  213
+            _log.Log(LogLevel.Error, format, args);
  214
+        }
  215
+
  216
+        public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args)
  217
+        {
  218
+            _log.Log(LogLevel.Fatal, formatProvider, format, args);
  219
+        }
  220
+
  221
+        public void FatalFormat(string format, params object[] args)
  222
+        {
  223
+            _log.Log(LogLevel.Fatal, format, args);
  224
+        }
  225
+
  226
+        LogLevel GetNLogLevel(LoggingLevel level)
  227
+        {
  228
+            if (level == LoggingLevel.Fatal)
  229
+                return LogLevel.Fatal;
  230
+            if (level == LoggingLevel.Error)
  231
+                return LogLevel.Error;
  232
+            if (level == LoggingLevel.Warn)
  233
+                return LogLevel.Warn;
  234
+            if (level == LoggingLevel.Info)
  235
+                return LogLevel.Info;
  236
+            if (level == LoggingLevel.Debug)
  237
+                return LogLevel.Debug;
  238
+            if (level == LoggingLevel.All)
  239
+                return LogLevel.Trace;
  240
+
  241
+            return LogLevel.Off;
  242
+        }
  243
+
  244
+        LogMessageGenerator ToGenerator(LogWriterOutputProvider provider)
  245
+        {
  246
+            return () =>
  247
+                {
  248
+                    object obj = provider();
  249
+                    return obj == null
  250
+                               ? ""
  251
+                               : obj.ToString();
  252
+                };
  253
+        }
  254
+    }
  255
+}
47  src/Topshelf.NLog/Logging/NLogLogWriterFactory.cs
... ...
@@ -0,0 +1,47 @@
  1
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
  2
+//  
  3
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
  4
+// this file except in compliance with the License. You may obtain a copy of the 
  5
+// License at 
  6
+// 
  7
+//     http://www.apache.org/licenses/LICENSE-2.0 
  8
+// 
  9
+// Unless required by applicable law or agreed to in writing, software distributed 
  10
+// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
  11
+// CONDITIONS OF ANY KIND, either express or implied. See the License for the 
  12
+// specific language governing permissions and limitations under the License.