Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added logging integrations, verified service behavior under control

  • Loading branch information...
commit 0c3f563444ef11bfb24fa69656c2a5eafe3c21ef 1 parent f70d297
@phatboyg authored
Showing with 1,193 additions and 441 deletions.
  1. +1 −1  .semver
  2. +53 −9 rakefile.rb
  3. +0 −6 src/.nuget/NuGet.Config
  4. +0 −139 src/.nuget/NuGet.targets
  5. BIN  src/.nuget/nuget.exe
  6. +0 −4 src/.nuget/packages.config
  7. +9 −1 src/SampleTopshelfService/SampleService.cs
  8. +1 −1  src/SolutionVersion.cs
  9. +54 −0 src/Topshelf.Log4Net/Log4NetConfigurationExtensions.cs
  10. +264 −0 src/Topshelf.Log4Net/Logging/Log4NetLogWriter.cs
  11. +48 −0 src/Topshelf.Log4Net/Logging/Log4NetLogWriterFactory.cs
  12. +78 −0 src/Topshelf.Log4Net/Topshelf.Log4Net.csproj
  13. +4 −0 src/Topshelf.Log4Net/packages.config
  14. +255 −0 src/Topshelf.NLog/Logging/NLogLogWriter.cs
  15. +47 −0 src/Topshelf.NLog/Logging/NLogLogWriterFactory.cs
  16. +43 −0 src/Topshelf.NLog/NLogConfiguratorExtensions.cs
  17. +77 −0 src/Topshelf.NLog/Topshelf.NLog.csproj
  18. +4 −0 src/Topshelf.NLog/packages.config
  19. +6 −6 src/Topshelf.Tests/Topshelf.Tests.csproj
  20. +2 −1  src/Topshelf.Tests/packages.config
  21. +23 −7 src/Topshelf.sln
  22. +1 −1  src/Topshelf/Configuration/Builders/RunBuilder.cs
  23. +3 −1 src/Topshelf/Configuration/Configurators/ValidateConfigurationResult.cs
  24. +1 −1  src/Topshelf/Configuration/HostConfigurators/HostConfiguratorImpl.cs
  25. +1 −1  src/Topshelf/HostFactory.cs
  26. +2 −2 src/Topshelf/Hosts/ConsoleRunHost.cs
  27. +1 −1  src/Topshelf/Hosts/InstallHost.cs
  28. +1 −1  src/Topshelf/Hosts/StartHost.cs
  29. +1 −1  src/Topshelf/Hosts/StopHost.cs
  30. +1 −1  src/Topshelf/Hosts/UninstallHost.cs
  31. +1 −1  src/Topshelf/Internals
  32. +82 −0 src/Topshelf/Logging/HostLogger.cs
  33. +11 −11 src/Topshelf/Logging/{Log.cs → LogWriter.cs}
  34. +2 −2 src/Topshelf/Logging/{ILogger.cs → LogWriterFactory.cs}
  35. +1 −1  src/Topshelf/Logging/{LogOutputProvider.cs → LogWriterOutputProvider.cs}
  36. +0 −143 src/Topshelf/Logging/Logger.cs
  37. +15 −15 src/Topshelf/Logging/{LogLevel.cs → LoggingLevel.cs}
  38. +56 −56 src/Topshelf/Logging/{TraceLog.cs → TraceLogWriter.cs}
  39. +9 −9 src/Topshelf/Logging/{TraceLogger.cs → TraceLogWriterFactory.cs}
  40. +1 −1  src/Topshelf/Runtime/Windows/HostInstaller.cs
  41. +2 −2 src/Topshelf/Runtime/Windows/WindowsHostEnvironment.cs
  42. +1 −1  src/Topshelf/Runtime/Windows/WindowsServiceControlManager.cs
  43. +23 −6 src/Topshelf/Runtime/Windows/WindowsServiceHost.cs
  44. +1 −1  src/Topshelf/Runtime/Windows/WindowsUserAccessControl.cs
  45. +7 −7 src/Topshelf/Topshelf.csproj
View
2  .semver
@@ -1,5 +1,5 @@
---
:patch: 0
-:special: prerelease
+:special: ""
:major: 3
:minor: 0
View
62 rakefile.rb
@@ -55,11 +55,15 @@
task :compile => [:versioning, :global_version, :build4, :tests4, :copy4, :build35, :tests35, :copy35]
task :copy35 => [:build35] do
- copyOutputFiles File.join(props[:src], "Topshelf/bin/Release/v3.5"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
+ copyOutputFiles File.join(props[:src], "Topshelf/bin/Release/v3.5"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
+ copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release/v3.5"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
+ copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release/v3.5"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-3.5')
end
task :copy4 => [:build4] do
- copyOutputFiles File.join(props[:src], "Topshelf/bin/Release"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
+ copyOutputFiles File.join(props[:src], "Topshelf/bin/Release"), "Topshelf.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
+ copyOutputFiles File.join(props[:src], "Topshelf.Log4Net/bin/Release"), "Topshelf.Log4Net.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
+ copyOutputFiles File.join(props[:src], "Topshelf.NLog/bin/Release"), "Topshelf.NLog.{dll,pdb,xml}", File.join(props[:output], 'net-4.0-full')
end
desc "Only compiles the application."
@@ -90,14 +94,14 @@ def copyOutputFiles(fromDir, filePattern, outDir)
desc "Runs unit tests"
nunit :tests35 => [:build35] do |nunit|
- nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.0.12051', 'tools', 'nunit-console.exe')
+ nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.1', 'tools', 'nunit-console.exe')
nunit.options = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results-net-3.5.xml')}\""
nunit.assemblies = FileList[File.join(props[:src], "Topshelf.Tests/bin/Release", "Topshelf.Tests.dll")]
end
desc "Runs unit tests"
nunit :tests4 => [:build4] do |nunit|
- nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.0.12051', 'tools', 'nunit-console.exe')
+ nunit.command = File.join('src', 'packages','NUnit.Runners.2.6.1', 'tools', 'nunit-console.exe')
nunit.options = "/framework=#{CLR_TOOLS_VERSION}", '/nothread', '/nologo', '/labels', "\"/xml=#{File.join(props[:artifacts], 'nunit-test-results-net-4.0.xml')}\""
nunit.assemblies = FileList[File.join(props[:src], "Topshelf.Tests/bin/Release", "Topshelf.Tests.dll")]
end
@@ -113,21 +117,23 @@ def copyOutputFiles(fromDir, filePattern, outDir)
desc "Restore NuGet Packages"
task :nuget_restore do
+ 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")}"
+ 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")}"
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")}"
- 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")}"
end
desc "Builds the nuget package"
task :nuget => [:versioning, :create_nuspec] do
- sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
+ sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
+ sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.Log4Net.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
+ sh "#{File.join(props[:lib], 'nuget.exe')} pack #{props[:artifacts]}/Topshelf.NLog.nuspec /Symbols /OutputDirectory #{props[:artifacts]}"
end
-task :create_nuspec => [:main_nuspec]
-
-nuspec :main_nuspec do |nuspec|
+nuspec :create_nuspec do |nuspec|
nuspec.id = 'Topshelf'
nuspec.version = NUGET_VERSION
nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
+ nuspec.summary = 'Topshelf, Friction-free Windows Services'
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.'
nuspec.title = 'Topshelf'
nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
@@ -140,6 +146,44 @@ def copyOutputFiles(fromDir, filePattern, outDir)
nuspec.file(File.join(props[:src], "Topshelf\\**\\*.cs").gsub("/","\\"), "src")
end
+nuspec :create_nuspec do |nuspec|
+ nuspec.id = 'Topshelf.Log4Net'
+ nuspec.version = NUGET_VERSION
+ nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
+ nuspec.summary = 'Topshelf, Friction-free Windows Services'
+ 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.'
+ nuspec.title = 'Topshelf.Log4Net'
+ nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
+ nuspec.iconUrl = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
+ nuspec.language = "en-US"
+ nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
+ nuspec.requireLicenseAcceptance = "false"
+ nuspec.dependency "Topshelf", NUGET_VERSION
+ nuspec.dependency "Log4Net", "2.0.0"
+ nuspec.output_file = File.join(props[:artifacts], 'Topshelf.Log4Net.nuspec')
+ add_files props[:output], 'Topshelf.Log4Net.{dll,pdb,xml}', nuspec
+ nuspec.file(File.join(props[:src], "Topshelf.Log4Net\\**\\*.cs").gsub("/","\\"), "src")
+end
+
+nuspec :create_nuspec do |nuspec|
+ nuspec.id = 'Topshelf.NLog'
+ nuspec.version = NUGET_VERSION
+ nuspec.authors = 'Chris Patterson, Dru Sellers, Travis Smith'
+ nuspec.summary = 'Topshelf, Friction-free Windows Services'
+ 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.'
+ nuspec.title = 'Topshelf.NLog'
+ nuspec.projectUrl = 'http://github.com/Topshelf/Topshelf'
+ nuspec.iconUrl = 'http://topshelf-project.com/wp-content/themes/pandora/slide.1.png'
+ nuspec.language = "en-US"
+ nuspec.licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0"
+ nuspec.requireLicenseAcceptance = "false"
+ nuspec.dependency "Topshelf", NUGET_VERSION
+ nuspec.dependency "NLog", "2.0"
+ nuspec.output_file = File.join(props[:artifacts], 'Topshelf.NLog.nuspec')
+ add_files props[:output], 'Topshelf.NLog.{dll,pdb,xml}', nuspec
+ nuspec.file(File.join(props[:src], "Topshelf.NLog\\**\\*.cs").gsub("/","\\"), "src")
+end
+
def project_outputs(props)
props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
View
6 src/.nuget/NuGet.Config
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<configuration>
- <solution>
- <add key="disableSourceControlIntegration" value="true" />
- </solution>
-</configuration>
View
139 src/.nuget/NuGet.targets
@@ -1,139 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
-
- <!-- Enable the restore command to run before builds -->
- <RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
-
- <!-- Property that enables building a package from a project -->
- <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
-
- <!-- Download NuGet.exe if it does not already exist -->
- <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
- </PropertyGroup>
-
- <ItemGroup Condition=" '$(PackageSources)' == '' ">
- <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
- <!--
- <PackageSource Include="https://nuget.org/api/v2/" />
- <PackageSource Include="https://my-nuget-source/nuget/" />
- -->
- </ItemGroup>
-
- <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
- <!-- Windows specific commands -->
- <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
- <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
- <PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
- <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
- <NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
- <PackagesConfig>packages.config</PackagesConfig>
- <PackagesDir>$(SolutionDir)packages</PackagesDir>
- </PropertyGroup>
-
- <PropertyGroup>
- <!-- NuGet command -->
- <NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
- <PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
-
- <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
- <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
-
- <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
-
- <!-- Commands -->
- <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" -o "$(PackagesDir)"</RestoreCommand>
- <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
-
- <!-- Make the build depend on restore packages -->
- <BuildDependsOn Condition="$(RestorePackages) == 'true'">
- RestorePackages;
- $(BuildDependsOn);
- </BuildDependsOn>
-
- <!-- Make the build depend on restore packages -->
- <BuildDependsOn Condition="$(BuildPackage) == 'true'">
- $(BuildDependsOn);
- BuildPackage;
- </BuildDependsOn>
- </PropertyGroup>
-
- <Target Name="CheckPrerequisites">
- <!-- Raise an error if we're unable to locate nuget.exe -->
- <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
- <SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
- <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
- </Target>
-
- <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
- <Exec Command="$(RestoreCommand)"
- Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
-
- <Exec Command="$(RestoreCommand)"
- LogStandardErrorAsError="true"
- Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
- </Target>
-
- <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
- <Exec Command="$(BuildCommand)"
- Condition=" '$(OS)' != 'Windows_NT' " />
-
- <Exec Command="$(BuildCommand)"
- LogStandardErrorAsError="true"
- Condition=" '$(OS)' == 'Windows_NT' " />
- </Target>
-
- <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
- <ParameterGroup>
- <OutputFilename ParameterType="System.String" Required="true" />
- </ParameterGroup>
- <Task>
- <Reference Include="System.Core" />
- <Using Namespace="System" />
- <Using Namespace="System.IO" />
- <Using Namespace="System.Net" />
- <Using Namespace="Microsoft.Build.Framework" />
- <Using Namespace="Microsoft.Build.Utilities" />
- <Code Type="Fragment" Language="cs">
- <![CDATA[
- try {
- OutputFilename = Path.GetFullPath(OutputFilename);
-
- Log.LogMessage("Downloading latest version of NuGet.exe...");
- WebClient webClient = new WebClient();
- webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
-
- return true;
- }
- catch (Exception ex) {
- Log.LogErrorFromException(ex);
- return false;
- }
- ]]>
- </Code>
- </Task>
- </UsingTask>
-
- <UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
- <ParameterGroup>
- <EnvKey ParameterType="System.String" Required="true" />
- <EnvValue ParameterType="System.String" Required="true" />
- </ParameterGroup>
- <Task>
- <Using Namespace="System" />
- <Code Type="Fragment" Language="cs">
- <![CDATA[
- try {
- Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
- }
- catch {
- }
- ]]>
- </Code>
- </Task>
- </UsingTask>
-</Project>
View
BIN  src/.nuget/nuget.exe
Binary file not shown
View
4 src/.nuget/packages.config
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
- <package id="NUnit.Runners" version="2.6.0.12051" />
-</packages>
View
10 src/SampleTopshelfService/SampleService.cs
@@ -20,7 +20,7 @@ namespace SampleTopshelfService
class SampleService :
ServiceControl
{
- static readonly Log _log = Logger.Get<SampleService>();
+ static readonly LogWriter _log = HostLogger.Get<SampleService>();
public bool Start(HostControl hostControl)
{
@@ -30,6 +30,14 @@ public bool Start(HostControl hostControl)
Thread.Sleep(1000);
+ ThreadPool.QueueUserWorkItem(x =>
+ {
+ Thread.Sleep(3000);
+
+ _log.Info("Requesting stop");
+
+ hostControl.Stop();
+ });
_log.Info("SampleService Started");
return true;
View
2  src/SolutionVersion.cs
@@ -9,5 +9,5 @@
[assembly: ComVisibleAttribute(false)]
[assembly: CLSCompliantAttribute(true)]
-[assembly: AssemblyInformationalVersion("3.0.0-prerelease.251b83")]
+[assembly: AssemblyInformationalVersion("3.0.0.f70d29")]
View
54 src/Topshelf.Log4Net/Log4NetConfigurationExtensions.cs
@@ -0,0 +1,54 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf
+{
+ using System;
+ using System.IO;
+ using HostConfigurators;
+ using Logging;
+
+ /// <summary>
+ /// Extensions for configuring Logging for log4net
+ /// </summary>
+ public static class Log4NetConfigurationExtensions
+ {
+ /// <summary>
+ /// Specify that you want to use the Log4net logging engine.
+ /// </summary>
+ /// <param name="configurator"> </param>
+ public static void UseLog4Net(this HostConfigurator configurator)
+ {
+ Log4NetLogWriterFactory.Use();
+ }
+
+ /// <summary>
+ /// Specify that you want to use the Log4net logging engine.
+ /// </summary>
+ /// <param name="configurator"> </param>
+ /// <param name="configFileName"> The name of the log4net xml configuration file </param>
+ public static void UseLog4Net(this HostConfigurator configurator, string configFileName)
+ {
+ Log4NetLogWriterFactory.Use();
+
+ string path = AppDomain.CurrentDomain.BaseDirectory;
+
+ string file = Path.Combine(path, configFileName);
+
+ var configFile = new FileInfo(file);
+ if (configFile.Exists)
+ {
+ Log4NetLogWriterFactory.Use(file);
+ }
+ }
+ }
+}
View
264 src/Topshelf.Log4Net/Logging/Log4NetLogWriter.cs
@@ -0,0 +1,264 @@
+// Copyright 2007-2011 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf.Logging
+{
+ using System;
+ using System.Globalization;
+ using Topshelf.Logging;
+
+ public class Log4NetLogWriter :
+ LogWriter
+ {
+ readonly log4net.ILog _log;
+
+ public Log4NetLogWriter(log4net.ILog log)
+ {
+ _log = log;
+ }
+
+ public void Debug(object message)
+ {
+ _log.Debug(message);
+ }
+
+ public void Debug(object message, Exception exception)
+ {
+ _log.Debug(message, exception);
+ }
+
+ public void Debug(LogWriterOutputProvider messageProvider)
+ {
+ if (!IsDebugEnabled)
+ return;
+
+ _log.Debug(messageProvider());
+ }
+
+ public void DebugFormat(string format, params object[] args)
+ {
+ _log.DebugFormat(format, args);
+ }
+
+ public void DebugFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ _log.DebugFormat(provider, format, args);
+ }
+
+ public void Info(object message)
+ {
+ _log.Info(message);
+ }
+
+ public void Info(object message, Exception exception)
+ {
+ _log.Info(message, exception);
+ }
+
+ public void Info(LogWriterOutputProvider messageProvider)
+ {
+ if (!IsInfoEnabled)
+ return;
+
+ _log.Info(messageProvider());
+ }
+
+ public void InfoFormat(string format, params object[] args)
+ {
+ _log.InfoFormat(format, args);
+ }
+
+ public void InfoFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ _log.InfoFormat(provider, format, args);
+ }
+
+ public void Warn(object message)
+ {
+ _log.Warn(message);
+ }
+
+ public void Warn(object message, Exception exception)
+ {
+ _log.Warn(message, exception);
+ }
+
+ public void Warn(LogWriterOutputProvider messageProvider)
+ {
+ if (!IsWarnEnabled)
+ return;
+
+ _log.Warn(messageProvider());
+ }
+
+ public void WarnFormat(string format, params object[] args)
+ {
+ _log.WarnFormat(format, args);
+ }
+
+ public void WarnFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ _log.WarnFormat(provider, format, args);
+ }
+
+ public void Error(object message)
+ {
+ _log.Error(message);
+ }
+
+ public void Error(object message, Exception exception)
+ {
+ _log.Error(message, exception);
+ }
+
+ public void Error(LogWriterOutputProvider messageProvider)
+ {
+ if (!IsErrorEnabled)
+ return;
+
+ _log.Error(messageProvider());
+ }
+
+ public void ErrorFormat(string format, params object[] args)
+ {
+ _log.ErrorFormat(format, args);
+ }
+
+ public void ErrorFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ _log.ErrorFormat(provider, format, args);
+ }
+
+ public void Fatal(object message)
+ {
+ _log.Fatal(message);
+ }
+
+ public void Fatal(object message, Exception exception)
+ {
+ _log.Fatal(message, exception);
+ }
+
+ public void Fatal(LogWriterOutputProvider messageProvider)
+ {
+ if (!IsFatalEnabled)
+ return;
+
+ _log.Fatal(messageProvider());
+ }
+
+ public void FatalFormat(string format, params object[] args)
+ {
+ _log.FatalFormat(format, args);
+ }
+
+ public void FatalFormat(IFormatProvider provider, string format, params object[] args)
+ {
+ _log.FatalFormat(provider, format, args);
+ }
+
+ public bool IsDebugEnabled
+ {
+ get { return _log.IsDebugEnabled; }
+ }
+
+ public bool IsInfoEnabled
+ {
+ get { return _log.IsInfoEnabled; }
+ }
+
+ public bool IsWarnEnabled
+ {
+ get { return _log.IsWarnEnabled; }
+ }
+
+ public bool IsErrorEnabled
+ {
+ get { return _log.IsErrorEnabled; }
+ }
+
+ public bool IsFatalEnabled
+ {
+ get { return _log.IsFatalEnabled; }
+ }
+
+ public void Log(LoggingLevel level, object obj)
+ {
+ if (level == LoggingLevel.Fatal)
+ Fatal(obj);
+ else if (level == LoggingLevel.Error)
+ Error(obj);
+ else if (level == LoggingLevel.Warn)
+ Warn(obj);
+ else if (level == LoggingLevel.Info)
+ Info(obj);
+ else if (level >= LoggingLevel.Debug)
+ Debug(obj);
+ }
+
+ public void Log(LoggingLevel level, object obj, Exception exception)
+ {
+ if (level == LoggingLevel.Fatal)
+ Fatal(obj, exception);
+ else if (level == LoggingLevel.Error)
+ Error(obj, exception);
+ else if (level == LoggingLevel.Warn)
+ Warn(obj, exception);
+ else if (level == LoggingLevel.Info)
+ Info(obj, exception);
+ else if (level >= LoggingLevel.Debug)
+ Debug(obj, exception);
+ }
+
+ public void Log(LoggingLevel level, LogWriterOutputProvider messageProvider)
+ {
+ if (level == LoggingLevel.Fatal)
+ Fatal(messageProvider);
+ else if (level == LoggingLevel.Error)
+ Error(messageProvider);
+ else if (level == LoggingLevel.Warn)
+ Warn(messageProvider);
+ else if (level == LoggingLevel.Info)
+ Info(messageProvider);
+ else if (level >= LoggingLevel.Debug)
+ Debug(messageProvider);
+ }
+
+ public void LogFormat(LoggingLevel level, string format, params object[] args)
+ {
+ if (level == LoggingLevel.Fatal)
+ FatalFormat(CultureInfo.InvariantCulture, format, args);
+ else if (level == LoggingLevel.Error)
+ ErrorFormat(CultureInfo.InvariantCulture, format, args);
+ else if (level == LoggingLevel.Warn)
+ WarnFormat(CultureInfo.InvariantCulture, format, args);
+ else if (level == LoggingLevel.Info)
+ InfoFormat(CultureInfo.InvariantCulture, format, args);
+ else if (level >= LoggingLevel.Debug)
+ DebugFormat(CultureInfo.InvariantCulture, format, args);
+ }
+
+ public void LogFormat(LoggingLevel level, IFormatProvider formatProvider, string format, params object[] args)
+ {
+ if (level == LoggingLevel.Fatal)
+ FatalFormat(formatProvider, format, args);
+ else if (level == LoggingLevel.Error)
+ ErrorFormat(formatProvider, format, args);
+ else if (level == LoggingLevel.Warn)
+ WarnFormat(formatProvider, format, args);
+ else if (level == LoggingLevel.Info)
+ InfoFormat(formatProvider, format, args);
+ else if (level >= LoggingLevel.Debug)
+ DebugFormat(formatProvider, format, args);
+ }
+ }
+}
View
48 src/Topshelf.Log4Net/Logging/Log4NetLogWriterFactory.cs
@@ -0,0 +1,48 @@
+// Copyright 2007-2011 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf.Logging
+{
+ using System;
+ using System.IO;
+ using Topshelf.Logging;
+ using log4net;
+ using log4net.Config;
+
+ public class Log4NetLogWriterFactory :
+ LogWriterFactory
+ {
+ public LogWriter Get(string name)
+ {
+ return new Log4NetLogWriter(LogManager.GetLogger(name));
+ }
+
+ public void Shutdown()
+ {
+ LogManager.Shutdown();
+ }
+
+ public static void Use()
+ {
+ HostLogger.UseLogger(new Log4NetLogWriterFactory());
+ }
+
+ public static void Use(string file)
+ {
+ HostLogger.UseLogger(new Log4NetLogWriterFactory());
+
+ file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, file);
+ var configFile = new FileInfo(file);
+ XmlConfigurator.Configure(configFile);
+ }
+ }
+}
View
78 src/Topshelf.Log4Net/Topshelf.Log4Net.csproj
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0EE64D46-5728-45DB-8D0E-044CE2677FD8}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Topshelf.Log4Net</RootNamespace>
+ <AssemblyName>Topshelf.Log4Net</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v3.5' ">
+ <DefineConstants>NET35</DefineConstants>
+ <OutputPath>bin\$(Configuration)\$(TargetFrameworkVersion)</OutputPath>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="log4net" Condition="'$(TargetFrameworkVersion)' == 'v3.5'">
+ <HintPath>..\packages\log4net.2.0.0\lib\net35-full\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="log4net" Condition="'$(TargetFrameworkVersion)' != 'v3.5'">
+ <HintPath>..\packages\log4net.2.0.0\lib\net40-full\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\SolutionVersion.cs">
+ <Link>SolutionVersion.cs</Link>
+ </Compile>
+ <Compile Include="Log4NetConfigurationExtensions.cs" />
+ <Compile Include="Logging\Log4NetLogWriter.cs" />
+ <Compile Include="Logging\Log4NetLogWriterFactory.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Topshelf\Topshelf.csproj">
+ <Project>{A52AD64D-6455-4A22-8CCF-581851086578}</Project>
+ <Name>Topshelf</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Properties\" />
+ </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>
View
4 src/Topshelf.Log4Net/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="log4net" version="2.0.0" targetFramework="net40" />
+</packages>
View
255 src/Topshelf.NLog/Logging/NLogLogWriter.cs
@@ -0,0 +1,255 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf.Logging
+{
+ using System;
+ using NLog;
+
+ /// <summary>
+ /// A logger that wraps to NLog. See http://stackoverflow.com/questions/7412156/how-to-retain-callsite-information-when-wrapping-nlog
+ /// </summary>
+ public class NLogLogWriter :
+ LogWriter
+ {
+ readonly Logger _log;
+
+ /// <summary>
+ /// Create a new NLog logger instance.
+ /// </summary>
+ /// <param name="log"> </param>
+ /// <param name="name"> Name of type to log as. </param>
+ public NLogLogWriter(Logger log, string name)
+ {
+ if (name == null)
+ throw new ArgumentNullException("name");
+ _log = log;
+ }
+
+ public bool IsDebugEnabled
+ {
+ get { return _log.IsDebugEnabled; }
+ }
+
+ public bool IsInfoEnabled
+ {
+ get { return _log.IsInfoEnabled; }
+ }
+
+ public bool IsWarnEnabled
+ {
+ get { return _log.IsWarnEnabled; }
+ }
+
+ public bool IsErrorEnabled
+ {
+ get { return _log.IsErrorEnabled; }
+ }
+
+ public bool IsFatalEnabled
+ {
+ get { return _log.IsFatalEnabled; }
+ }
+
+ public void Log(LoggingLevel level, object obj)
+ {
+ _log.Log(GetNLogLevel(level), obj);
+ }
+
+ public void Log(LoggingLevel level, object obj, Exception exception)
+ {
+ _log.LogException(GetNLogLevel(level), obj == null
+ ? ""
+ : obj.ToString(), exception);
+ }
+
+ public void Log(LoggingLevel level, LogWriterOutputProvider messageProvider)
+ {
+ _log.Log(GetNLogLevel(level), ToGenerator(messageProvider));
+ }
+
+ public void LogFormat(LoggingLevel level, IFormatProvider formatProvider, string format,
+ params object[] args)
+ {
+ _log.Log(GetNLogLevel(level), formatProvider, format, args);
+ }
+
+ public void LogFormat(LoggingLevel level, string format, params object[] args)
+ {
+ _log.Log(GetNLogLevel(level), format, args);
+ }
+
+ public void Debug(object obj)
+ {
+ _log.Log(LogLevel.Debug, obj);
+ }
+
+ public void Debug(object obj, Exception exception)
+ {
+ _log.LogException(LogLevel.Debug, obj == null
+ ? ""
+ : obj.ToString(), exception);
+ }
+
+ public void Debug(LogWriterOutputProvider messageProvider)
+ {
+ _log.Debug(ToGenerator(messageProvider));
+ }
+
+ public void Info(object obj)
+ {
+ _log.Log(LogLevel.Info, obj);
+ }
+
+ public void Info(object obj, Exception exception)
+ {
+ _log.LogException(LogLevel.Info, obj == null
+ ? ""
+ : obj.ToString(), exception);
+ }
+
+ public void Info(LogWriterOutputProvider messageProvider)
+ {
+ _log.Info(ToGenerator(messageProvider));
+ }
+
+ public void Warn(object obj)
+ {
+ _log.Log(LogLevel.Warn, obj);
+ }
+
+ public void Warn(object obj, Exception exception)
+ {
+ _log.LogException(LogLevel.Warn, obj == null
+ ? ""
+ : obj.ToString(), exception);
+ }
+
+ public void Warn(LogWriterOutputProvider messageProvider)
+ {
+ _log.Warn(ToGenerator(messageProvider));
+ }
+
+ public void Error(object obj)
+ {
+ _log.Log(LogLevel.Error, obj);
+ }
+
+ public void Error(object obj, Exception exception)
+ {
+ _log.LogException(LogLevel.Error, obj == null
+ ? ""
+ : obj.ToString(), exception);
+ }
+
+ public void Error(LogWriterOutputProvider messageProvider)
+ {
+ _log.Error(ToGenerator(messageProvider));
+ }
+
+ public void Fatal(object obj)
+ {
+ _log.Log(LogLevel.Fatal, obj);
+ }
+
+ public void Fatal(object obj, Exception exception)
+ {
+ _log.LogException(LogLevel.Fatal, obj == null
+ ? ""
+ : obj.ToString(), exception);
+ }
+
+ public void Fatal(LogWriterOutputProvider messageProvider)
+ {
+ _log.Fatal(ToGenerator(messageProvider));
+ }
+
+ public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args)
+ {
+ _log.Log(LogLevel.Debug, formatProvider, format, args);
+ }
+
+ public void DebugFormat(string format, params object[] args)
+ {
+ _log.Log(LogLevel.Debug, format, args);
+ }
+
+ public void InfoFormat(IFormatProvider formatProvider, string format, params object[] args)
+ {
+ _log.Log(LogLevel.Info, formatProvider, format, args);
+ }
+
+ public void InfoFormat(string format, params object[] args)
+ {
+ _log.Log(LogLevel.Info, format, args);
+ }
+
+ public void WarnFormat(IFormatProvider formatProvider, string format, params object[] args)
+ {
+ _log.Log(LogLevel.Warn, formatProvider, format, args);
+ }
+
+ public void WarnFormat(string format, params object[] args)
+ {
+ _log.Log(LogLevel.Warn, format, args);
+ }
+
+ public void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args)
+ {
+ _log.Log(LogLevel.Error, formatProvider, format, args);
+ }
+
+ public void ErrorFormat(string format, params object[] args)
+ {
+ _log.Log(LogLevel.Error, format, args);
+ }
+
+ public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args)
+ {
+ _log.Log(LogLevel.Fatal, formatProvider, format, args);
+ }
+
+ public void FatalFormat(string format, params object[] args)
+ {
+ _log.Log(LogLevel.Fatal, format, args);
+ }
+
+ LogLevel GetNLogLevel(LoggingLevel level)
+ {
+ if (level == LoggingLevel.Fatal)
+ return LogLevel.Fatal;
+ if (level == LoggingLevel.Error)
+ return LogLevel.Error;
+ if (level == LoggingLevel.Warn)
+ return LogLevel.Warn;
+ if (level == LoggingLevel.Info)
+ return LogLevel.Info;
+ if (level == LoggingLevel.Debug)
+ return LogLevel.Debug;
+ if (level == LoggingLevel.All)
+ return LogLevel.Trace;
+
+ return LogLevel.Off;
+ }
+
+ LogMessageGenerator ToGenerator(LogWriterOutputProvider provider)
+ {
+ return () =>
+ {
+ object obj = provider();
+ return obj == null
+ ? ""
+ : obj.ToString();
+ };
+ }
+ }
+}
View
47 src/Topshelf.NLog/Logging/NLogLogWriterFactory.cs
@@ -0,0 +1,47 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf.Logging
+{
+ using NLog;
+
+ public class NLogLogWriterFactory :
+ LogWriterFactory
+ {
+ readonly LogFactory _logFactory;
+
+ public NLogLogWriterFactory(LogFactory logFactory)
+ {
+ _logFactory = logFactory;
+ }
+
+ public NLogLogWriterFactory()
+ : this(new LogFactory())
+ {
+ }
+
+ public LogWriter Get(string name)
+ {
+ return new NLogLogWriter(_logFactory.GetLogger(name), name);
+ }
+
+ public void Shutdown()
+ {
+ _logFactory.Dispose();
+ }
+
+ public static void Use()
+ {
+ HostLogger.UseLogger(new NLogLogWriterFactory());
+ }
+ }
+}
View
43 src/Topshelf.NLog/NLogConfiguratorExtensions.cs
@@ -0,0 +1,43 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf
+{
+ using HostConfigurators;
+ using Logging;
+ using NLog;
+
+ /// <summary>
+ /// Extensions for configuring NLog with MassTransit
+ /// </summary>
+ public static class NLogConfiguratorExtensions
+ {
+ /// <summary>
+ /// Specify that you want to use the NLog logging framework.
+ /// </summary>
+ /// <param name="configurator"> Optional service bus configurator </param>
+ public static void UseNLog(this HostConfigurator configurator)
+ {
+ NLogLogWriterFactory.Use();
+ }
+
+ /// <summary>
+ /// Specify that you want to use the NLog logging framework.
+ /// </summary>
+ /// <param name="configurator"> Optional service bus configurator </param>
+ /// <param name="factory"> Required log-producing factory from NLog </param>
+ public static void UseNLog(this HostConfigurator configurator, LogFactory factory)
+ {
+ HostLogger.UseLogger(new NLogLogWriterFactory(factory));
+ }
+ }
+}
View
77 src/Topshelf.NLog/Topshelf.NLog.csproj
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{55FC6F5C-778F-4E77-8C55-C62216858CE7}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Topshelf.NLog</RootNamespace>
+ <AssemblyName>Topshelf.NLog</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <RestorePackages>true</RestorePackages>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v3.5' ">
+ <DefineConstants>NET35</DefineConstants>
+ <OutputPath>bin\$(Configuration)\$(TargetFrameworkVersion)</OutputPath>
+ </PropertyGroup>
+<ItemGroup>
+ <Reference Include="NLog" Condition="'$(TargetFrameworkVersion)' == 'v3.5'">
+ <HintPath>..\packages\NLog.2.0.0.2000\lib\net35\NLog.dll</HintPath>
+ </Reference>
+ <Reference Include="NLog" Condition="'$(TargetFrameworkVersion)' != 'v3.5'">
+ <HintPath>..\packages\NLog.2.0.0.2000\lib\net40\NLog.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\SolutionVersion.cs">
+ <Link>SolutionVersion.cs</Link>
+ </Compile>
+ <Compile Include="Logging\NLogLogWriter.cs" />
+ <Compile Include="Logging\NLogLogWriterFactory.cs" />
+ <Compile Include="NLogConfiguratorExtensions.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Topshelf\Topshelf.csproj">
+ <Project>{A52AD64D-6455-4A22-8CCF-581851086578}</Project>
+ <Name>Topshelf</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Properties\" />
+ </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>
View
4 src/Topshelf.NLog/packages.config
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="NLog" version="2.0.0.2000" targetFramework="net40" />
+</packages>
View
12 src/Topshelf.Tests/Topshelf.Tests.csproj
@@ -36,8 +36,9 @@
<DefineConstants>NET35</DefineConstants>
</PropertyGroup>
<ItemGroup>
- <Reference Include="nunit.framework">
- <HintPath>..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll</HintPath>
+ <Reference Include="nunit.framework, Version=2.6.1.12217, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\NUnit.2.6.1\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@@ -49,9 +50,6 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
@@ -60,8 +58,10 @@
</Compile>
<Compile Include="CommandLine_Specs.cs" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <Import Project="$(SolutionDir)\.nuget\nuget.targets" Condition="'$(TargetFrameworkVersion)' == 'v4.0'" />
<!-- 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">
View
3  src/Topshelf.Tests/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="NUnit" version="2.6.0.12054" targetFramework="net40" />
+ <package id="NUnit" version="2.6.1" targetFramework="net40" />
+ <package id="NUnit.Runners" version="2.6.1" />
</packages>
View
30 src/Topshelf.sln
@@ -9,13 +9,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleTopshelfService", "Sa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Topshelf.Tests", "Topshelf.Tests\Topshelf.Tests.csproj", "{508C7AAB-03DD-40C6-947D-6A8D22AAA941}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9AAB3240-AD6F-4A20-BD03-B612D652B49C}"
- ProjectSection(SolutionItems) = preProject
- .nuget\NuGet.Config = .nuget\NuGet.Config
- .nuget\nuget.exe = .nuget\nuget.exe
- .nuget\NuGet.targets = .nuget\NuGet.targets
- .nuget\packages.config = .nuget\packages.config
- EndProjectSection
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Topshelf.Log4Net", "Topshelf.Log4Net\Topshelf.Log4Net.csproj", "{0EE64D46-5728-45DB-8D0E-044CE2677FD8}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Topshelf.NLog", "Topshelf.NLog\Topshelf.NLog.csproj", "{55FC6F5C-778F-4E77-8C55-C62216858CE7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -59,6 +55,26 @@ Global
{508C7AAB-03DD-40C6-947D-6A8D22AAA941}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{508C7AAB-03DD-40C6-947D-6A8D22AAA941}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{508C7AAB-03DD-40C6-947D-6A8D22AAA941}.Release|x86.ActiveCfg = Release|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {0EE64D46-5728-45DB-8D0E-044CE2677FD8}.Release|x86.ActiveCfg = Release|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Release|Any CPU.Build.0 = Release|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {55FC6F5C-778F-4E77-8C55-C62216858CE7}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
2  src/Topshelf/Configuration/Builders/RunBuilder.cs
@@ -20,7 +20,7 @@ namespace Topshelf.Builders
public class RunBuilder :
HostBuilder
{
- static readonly Log _log = Logger.Get<RunBuilder>();
+ static readonly LogWriter _log = HostLogger.Get<RunBuilder>();
readonly EventCallbackList<HostStartedContext> _afterStart;
readonly EventCallbackList<HostStoppedContext> _afterStop;
View
4 src/Topshelf/Configuration/Configurators/ValidateConfigurationResult.cs
@@ -64,7 +64,9 @@ public static ConfigurationResult CompileResults(IEnumerable<ValidateResult> res
if (result.ContainsFailure)
{
- string message = "The service was not properly configured: " + result.Message;
+ string message = "The service was not properly configured: "
+ + Environment.NewLine
+ + result.Message;
throw new HostConfigurationException(message);
}
View
2  src/Topshelf/Configuration/HostConfigurators/HostConfiguratorImpl.cs
@@ -26,7 +26,7 @@ namespace Topshelf.HostConfigurators
public class HostConfiguratorImpl :
HostConfigurator
{
- static readonly Log _log = Logger.Get(typeof(HostConfiguratorImpl));
+ static readonly LogWriter _log = HostLogger.Get(typeof(HostConfiguratorImpl));
readonly IList<HostBuilderConfigurator> _configurators;
readonly WindowsHostSettings _settings;
View
2  src/Topshelf/HostFactory.cs
@@ -22,7 +22,7 @@ namespace Topshelf
/// </summary>
public static class HostFactory
{
- static readonly Log _log = Logger.Get(typeof(HostFactory));
+ static readonly LogWriter _log = HostLogger.Get(typeof(HostFactory));
/// <summary>
/// Configures a new service host
View
4 src/Topshelf/Hosts/ConsoleRunHost.cs
@@ -22,7 +22,7 @@ public class ConsoleRunHost :
Host,
HostControl
{
- static readonly Log _log = Logger.Get<ConsoleRunHost>();
+ static readonly LogWriter _log = HostLogger.Get<ConsoleRunHost>();
readonly HostEnvironment _environment;
readonly ServiceHandle _serviceHandle;
readonly HostSettings _settings;
@@ -77,7 +77,7 @@ public void Run()
_exit.Close();
(_exit as IDisposable).Dispose();
- Logger.Shutdown();
+ HostLogger.Shutdown();
}
}
View
2  src/Topshelf/Hosts/InstallHost.cs
@@ -22,7 +22,7 @@ namespace Topshelf.Hosts
public class InstallHost :
Host
{
- static readonly Log _log = Logger.Get<InstallHost>();
+ static readonly LogWriter _log = HostLogger.Get<InstallHost>();
readonly HostEnvironment _environment;
readonly InstallHostSettings _installSettings;
View
2  src/Topshelf/Hosts/StartHost.cs
@@ -20,7 +20,7 @@ public class StartHost :
Host
{
readonly HostEnvironment _environment;
- readonly Log _log = Logger.Get<StartHost>();
+ readonly LogWriter _log = HostLogger.Get<StartHost>();
readonly Host _parentHost;
HostSettings _settings;
View
2  src/Topshelf/Hosts/StopHost.cs
@@ -18,7 +18,7 @@ namespace Topshelf.Hosts
public class StopHost :
Host
{
- static readonly Log _log = Logger.Get<StopHost>();
+ static readonly LogWriter _log = HostLogger.Get<StopHost>();
readonly HostEnvironment _environment;
readonly HostSettings _settings;
View
2  src/Topshelf/Hosts/UninstallHost.cs
@@ -20,7 +20,7 @@ namespace Topshelf.Hosts
public class UninstallHost :
Host
{
- static readonly Log _log = Logger.Get<UninstallHost>();
+ static readonly LogWriter _log = HostLogger.Get<UninstallHost>();
readonly HostEnvironment _environment;
readonly IEnumerable<Action> _postActions;
2  src/Topshelf/Internals
@@ -1 +1 @@
-Subproject commit 8e386b2efa7da7ec04db141d07ccef17907769be
+Subproject commit f9044e3bafc1f90bfe61f2fa642c46e880b35e3f
View
82 src/Topshelf/Logging/HostLogger.cs
@@ -0,0 +1,82 @@
+// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
+//
+// Licensed 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 Topshelf.Logging
+{
+ using System;
+ using Internals.Extensions;
+
+ public static class HostLogger
+ {
+ static readonly object _locker = new object();
+ static LogWriterFactory _logger;
+
+ public static LogWriterFactory Current
+ {
+ get
+ {
+ lock (_locker)
+ {
+ return _logger ?? CreateTraceLogger();
+ }
+ }
+ }
+
+ static LogWriterFactory CreateTraceLogger()
+ {
+ _logger = new TraceLogWriterFactory();
+
+
+ return _logger;
+ }
+
+ public static LogWriter Get<T>()
+ where T : class
+ {
+ return Get(typeof(T).GetTypeName());
+ }
+
+ public static LogWriter Get(Type type)
+ {
+ return Get(type.GetTypeName());
+ }
+
+ static LogWriter Get(string name)
+ {
+ return Current.Get(name);
+ }
+
+ public static void UseLogger(LogWriterFactory logger)
+ {
+ lock (_locker)
+ {
+ if (_logger != null)
+ _logger.Shutdown();
+ _logger = null;
+
+ _logger = logger;
+ }
+ }
+
+ public static void Shutdown()
+ {
+ lock (_locker)
+ {
+ if (_logger != null)
+ {
+ _logger.Shutdown();
+ _logger = null;
+ }
+ }
+ }
+ }
+}
View
22 src/Topshelf/Logging/Log.cs → src/Topshelf/Logging/LogWriter.cs
@@ -17,7 +17,7 @@ namespace Topshelf.Logging
/// <summary>
/// Implementers handle logging and filtering based on logging levels.
/// </summary>
- public interface Log
+ public interface LogWriter
{
bool IsDebugEnabled { get; }
bool IsInfoEnabled { get; }
@@ -25,39 +25,39 @@ public interface Log
bool IsErrorEnabled { get; }
bool IsFatalEnabled { get; }
- void Log(LogLevel level, object obj);
- void Log(LogLevel level, object obj, Exception exception);
- void Log(LogLevel level, LogOutputProvider messageProvider);
- void LogFormat(LogLevel level, IFormatProvider formatProvider, string format, params object[] args);
- void LogFormat(LogLevel level, string format, params object[] args);
+ void Log(LoggingLevel level, object obj);
+ void Log(LoggingLevel level, object obj, Exception exception);
+ void Log(LoggingLevel level, LogWriterOutputProvider messageProvider);
+ void LogFormat(LoggingLevel level, IFormatProvider formatProvider, string format, params object[] args);
+ void LogFormat(LoggingLevel level, string format, params object[] args);
void Debug(object obj);
void Debug(object obj, Exception exception);
- void Debug(LogOutputProvider messageProvider);
+ void Debug(LogWriterOutputProvider messageProvider);
void DebugFormat(IFormatProvider formatProvider, string format, params object[] args);
void DebugFormat(string format, params object[] args);
void Info(object obj);
void Info(object obj, Exception exception);
- void Info(LogOutputProvider messageProvider);
+ void Info(LogWriterOutputProvider messageProvider);
void InfoFormat(IFormatProvider formatProvider, string format, params object[] args);
void InfoFormat(string format, params object[] args);
void Warn(object obj);
void Warn(object obj, Exception exception);
- void Warn(LogOutputProvider messageProvider);
+ void Warn(LogWriterOutputProvider messageProvider);
void WarnFormat(IFormatProvider formatProvider, string format, params object[] args);
void WarnFormat(string format, params object[] args);
void Error(object obj);
void Error(object obj, Exception exception);
- void Error(LogOutputProvider messageProvider);
+ void Error(LogWriterOutputProvider messageProvider);
void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args);
void ErrorFormat(string format, params object[] args);
void Fatal(object obj);
void Fatal(object obj, Exception exception);
- void Fatal(LogOutputProvider messageProvider);
+ void Fatal(LogWriterOutputProvider messageProvider);
void FatalFormat(IFormatProvider formatProvider, string format, params object[] args);
void FatalFormat(string format, params object[] args);
}
View
4 src/Topshelf/Logging/ILogger.cs → src/Topshelf/Logging/LogWriterFactory.cs
@@ -12,9 +12,9 @@
// specific language governing permissions and limitations under the License.
namespace Topshelf.Logging
{
- public interface ILogger
+ public interface LogWriterFactory
{
- Log Get(string name);
+ LogWriter Get(string name);
void Shutdown();
}
View
2  src/Topshelf/Logging/LogOutputProvider.cs → src/Topshelf/Logging/LogWriterOutputProvider.cs
@@ -16,5 +16,5 @@ namespace Topshelf.Logging
/// Delegate to provide the log output if the log level is enabled
/// </summary>
/// <returns></returns>
- public delegate object LogOutputProvider();
+ public delegate object LogWriterOutputProvider();
}
View
143 src/Topshelf/Logging/Logger.cs
@@ -1,143 +0,0 @@
-// Copyright 2007-2012 Chris Patterson, Dru Sellers, Travis Smith, et. al.
-//
-// Licensed 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 Topshelf.Logging
-{
- using System;
- using System.Text;
-
- public static class Logger
- {
- static readonly object _locker = new object();
- static ILogger _logger;
-
- public static ILogger Current
- {
- get
- {
- lock (_locker)
- {
- return _logger ?? CreateTraceLogger();
- }
- }
- }
-
- static ILogger CreateTraceLogger()
- {
- _logger = new TraceLogger();
-
-
- return _logger;
- }
-
- public static Log Get<T>()
- where T : class
- {
- return Get(GetCleanTypeName<T>());
- }
-
- public static Log Get(Type type)
- {
- return Get(GetCleanTypeName(type));
- }
-
- static Log Get(string name)
- {
- return Current.Get(name);
- }
-
- public static void UseLogger(ILogger logger)
- {
- lock (_locker)
- {
- if (_logger != null)
- _logger.Shutdown();
- _logger = null;
-
- _logger = logger;
- }
- }
-
- public static string GetCleanTypeName<T>()
- {
- return GetCleanTypeName(typeof(T));
- }
-
- public static string GetCleanTypeName(Type type)
- {
- return GetCleanTypeName(new StringBuilder(), type, null);
- }
-
- public static void Shutdown()
- {
- lock (_locker)
- {
- if (_logger != null)
- {
- _logger.Shutdown();
- _logger = null;
- }
- }
- }
-
- static string GetCleanTypeName(StringBuilder sb, Type type, string scope)
- {
- if (type.IsGenericParameter)
- return "";
-
- if (type.Namespace != null)
- {
- string ns = type.Namespace;
- if (!ns.Equals(scope))
- {
- sb.Append(ns);
- sb.Append(".");
- }
- }
-
- if (type.IsNested)
- {
- GetCleanTypeName(sb, type.DeclaringType, type.Namespace);
- sb.Append("+");
- }
-
- if (type.IsGenericType)
- {
- string name = type.GetGenericTypeDefinition().Name;
-
- int index = name.IndexOf('`');
- if (index > 0)
- name = name.Remove(index);
-
- sb.Append(name);
- sb.Append("<");
-
- Type[] arguments = type.GetGenericArguments();
- for (int i = 0; i < arguments.Length; i++)
- {
- if (i > 0)
- {
- sb.Append(",");
- }
-
- GetCleanTypeName(sb, arguments[i], type.Namespace);
- }
-
- sb.Append(">");
- }
- else
- sb.Append(type.Name);
-
- return sb.ToString();
- }
- }
-}
View
30 src/Topshelf/Logging/LogLevel.cs → src/Topshelf/Logging/LoggingLevel.cs
@@ -15,25 +15,25 @@ namespace Topshelf.Logging
using System.Collections.Generic;
using System.Diagnostics;
- public class LogLevel
+ public class LoggingLevel
{
- public static readonly LogLevel All = new LogLevel("All", 6, SourceLevels.All, TraceEventType.Verbose);
- public static readonly LogLevel Debug = new LogLevel("Debug", 5, SourceLevels.Verbose, TraceEventType.Verbose);
- public static readonly LogLevel Error = new LogLevel("Error", 2, SourceLevels.Error, TraceEventType.Error);
- public static readonly LogLevel Fatal = new LogLevel("Fatal", 1, SourceLevels.Critical, TraceEventType.Critical);
+ public static readonly LoggingLevel All = new LoggingLevel("All", 6, SourceLevels.All, TraceEventType.Verbose);
+ public static readonly LoggingLevel Debug = new LoggingLevel("Debug", 5, SourceLevels.Verbose, TraceEventType.Verbose);
+ public static readonly LoggingLevel Error = new LoggingLevel("Error", 2, SourceLevels.Error, TraceEventType.Error);
+ public static readonly LoggingLevel Fatal = new LoggingLevel("Fatal", 1, SourceLevels.Critical, TraceEventType.Critical);
- public static readonly LogLevel Info = new LogLevel("Info", 4, SourceLevels.Information,
+ public static readonly LoggingLevel Info = new LoggingLevel("Info", 4, SourceLevels.Information,
TraceEventType.Information);
- public static readonly LogLevel None = new LogLevel("None", 0, SourceLevels.Off, TraceEventType.Critical);
- public static readonly LogLevel Warn = new LogLevel("Warn", 3, SourceLevels.Warning, TraceEventType.Warning);
+ public static readonly LoggingLevel None = new LoggingLevel("None", 0, SourceLevels.Off, TraceEventType.Critical);
+ public static readonly LoggingLevel Warn = new LoggingLevel("Warn", 3, SourceLevels.Warning, TraceEventType.Warning);
readonly int _index;
readonly string _name;
readonly SourceLevels _sourceLevel;
readonly TraceEventType _traceEventType;
- LogLevel(string name, int index, SourceLevels sourceLevel, TraceEventType traceEventType)
+ LoggingLevel(string name, int index, SourceLevels sourceLevel, TraceEventType traceEventType)
{
_name = name;
_index = index;
@@ -41,7 +41,7 @@ public class LogLevel
_traceEventType = traceEventType;
}
- public static IEnumerable<LogLevel> Values
+ public static IEnumerable<LoggingLevel> Values
{
get
{
@@ -75,27 +75,27 @@ public override string ToString()
return _name;
}
- public static bool operator >(LogLevel left, LogLevel right)
+ public static bool operator >(LoggingLevel left, LoggingLevel right)
{
return right != null && (left != null && left._index > right._index);
}
- public static bool operator <(LogLevel left, LogLevel right)
+ public static bool operator <(LoggingLevel left, LoggingLevel right)
{
return right != null && (left != null && left._index < right._index);
}
- public static bool operator >=(LogLevel left, LogLevel right)
+ public static bool operator >=(LoggingLevel left, LoggingLevel right)
{
return right != null && (left != null && left._index >= right._index);
}
- public static bool operator <=(LogLevel left, LogLevel right)
+ public static bool operator <=(LoggingLevel left, LoggingLevel right)
{
return right != null && (left != null && left._index <= right._index);
}
- public static LogLevel FromSourceLevels(SourceLevels level)
+ public static LoggingLevel FromSourceLevels(SourceLevels level)
{
switch (level)
{
View
112 src/Topshelf/Logging/TraceLog.cs → src/Topshelf/Logging/TraceLogWriter.cs
@@ -16,44 +16,44 @@ namespace Topshelf.Logging
using System.Diagnostics;
using System.Globalization;
- public class TraceLog :
- Log
+ public class TraceLogWriter :
+ LogWriter
{
- readonly LogLevel _level;
+ readonly LoggingLevel _level;
readonly TraceSource _source;
- public TraceLog(TraceSource source)
+ public TraceLogWriter(TraceSource source)
{
_source = source;
- _level = LogLevel.FromSourceLevels(source.Switch.Level);
+ _level = LoggingLevel.FromSourceLevels(source.Switch.Level);
}
public bool IsDebugEnabled
{
- get { return _level >= LogLevel.Debug; }
+ get { return _level >= LoggingLevel.Debug; }
}
public bool IsInfoEnabled
{
- get { return _level >= LogLevel.Info; }
+ get { return _level >= LoggingLevel.Info; }
}
public bool IsWarnEnabled
{
- get { return _level >= LogLevel.Warn; }
+ get { return _level >= LoggingLevel.Warn; }
}
public bool IsErrorEnabled
{
- get { return _level >= LogLevel.Error; }
+ get { return _level >= LoggingLevel.Error; }
}
public bool IsFatalEnabled
{
- get { return _level >= LogLevel.Fatal; }
+ get { return _level >= LoggingLevel.Fatal; }
}
- public void LogFormat(LogLevel level, string format, params object[] args)
+ public void LogFormat(LoggingLevel level, string format, params object[] args)
{
if (_level < level)
return;
@@ -70,7 +70,7 @@ public void Debug(object message)
{
if (!IsDebugEnabled)
return;
- Log(LogLevel.Debug, message, null);
+ Log(LoggingLevel.Debug, message, null);
}
/// <summary>
@@ -83,17 +83,17 @@ public void Debug(object message, Exception exception)
{
if (!IsDebugEnabled)
return;
- Log(LogLevel.Debug, message, exception);
+ Log(LoggingLevel.Debug, message, exception);
}
- public void Debug(LogOutputProvider messageProvider)
+ public void Debug(LogWriterOutputProvider messageProvider)
{
if (!IsDebugEnabled)
return;
object obj = messageProvider();
- LogInternal(LogLevel.Debug, obj, null);
+ LogInternal(LoggingLevel.Debug, obj, null);
}
/// <summary>
@@ -106,7 +106,7 @@ public void DebugFormat(string format, params object[] args)
{
if (!IsDebugEnabled)
return;
- LogInternal(LogLevel.Debug, string.Format(CultureInfo.CurrentCulture, format, args), null);
+ LogInternal(LoggingLevel.Debug, string.Format(CultureInfo.CurrentCulture, format, args), null);
}
/// <summary>
@@ -120,7 +120,7 @@ public void DebugFormat(IFormatProvider formatProvider, string format, params ob
{
if (!IsDebugEnabled)
return;
- LogInternal(LogLevel.Debug, string.Format(formatProvider, format, args), null);
+ LogInternal(LoggingLevel.Debug, string.Format(formatProvider, format, args), null);
}
/// <summary>
@@ -132,7 +132,7 @@ public void Info(object message)
{
if (!IsInfoEnabled)
return;
- Log(LogLevel.Info, message, null);
+ Log(LoggingLevel.Info, message, null);
}
/// <summary>
@@ -145,17 +145,17 @@ public void Info(object message, Exception exception)
{
if (!IsInfoEnabled)
return;
- Log(LogLevel.Info, message, exception);
+ Log(LoggingLevel.Info, message, exception);
}
- public void Info(LogOutputProvider messageProvider)
+ public void Info(LogWriterOutputProvider messageProvider)
{
if (!IsInfoEnabled)
return;
object obj = messageProvider();
- LogInternal(LogLevel.Info, obj, null);
+ LogInternal(LoggingLevel.Info, obj, null);
}
/// <summary>
@@ -168,7 +168,7 @@ public void InfoFormat(string format, params object[] args)
{
if (!IsInfoEnabled)
return;
- LogInternal(LogLevel.Info, string.Format(CultureInfo.CurrentCulture, format, args), null);
+ LogInternal(LoggingLevel.Info, string.Format(CultureInfo.CurrentCulture, format, args), null);
}
/// <summary>
@@ -182,7 +182,7 @@ public void InfoFormat(IFormatProvider formatProvider, string format, params obj
{
if (!IsInfoEnabled)
return;
- LogInternal(LogLevel.Info, string.Format(formatProvider, format, args), null);
+ LogInternal(LoggingLevel.Info, string.Format(formatProvider, format, args), null);
}
/// <summary>
@@ -194,7 +194,7 @@ public void Warn(object message)
{
if (!IsWarnEnabled)
return;
- Log(LogLevel.Warn, message, null);
+ Log(LoggingLevel.Warn, message, null);
}
/// <summary>
@@ -207,17 +207,17 @@ public void Warn(object message, Exception exception)
{
if (!IsWarnEnabled)
return;
- Log(LogLevel.Warn, message, exception);
+ Log(LoggingLevel.Warn, message, exception);
}
- public void Warn(LogOutputProvider messageProvider)
+ public void Warn(LogWriterOutputProvider messageProvider)
{
if (!IsWarnEnabled)
return;
object obj = messageProvider();
- LogInternal(LogLevel.Warn, obj, null);
+ LogInternal(LoggingLevel.Warn, obj, null);
}
/// <summary>
@@ -230,7 +230,7 @@ public void WarnFormat(string format, params object[] args)
{
if (!IsWarnEnabled)
return;
- LogInternal(LogLevel.Warn, string.Format(CultureInfo.CurrentCulture, format, args), null);
+ LogInternal(LoggingLevel.Warn, string.Format(CultureInfo.CurrentCulture, format, args), null);
}
/// <summary>
@@ -244,7 +244,7 @@ public void WarnFormat(IFormatProvider formatProvider, string format, params obj
{
if (!IsWarnEnabled)
return;
- LogInternal(LogLevel.Warn, string.Format(formatProvider, format, args), null);
+ LogInternal(LoggingLevel.Warn, string.Format(formatProvider, format, args), null);
}
/// <summary>
@@ -256,7 +256,7 @@ public void Error(object message)
{
if (!IsErrorEnabled)
return;
- Log(LogLevel.Error, message, null);
+ Log(LoggingLevel.Error, message, null);
}
/// <summary>
@@ -269,17 +269,17 @@ public void Error(object message, Exception exception)
{
if (!IsErrorEnabled)
return;
- Log(LogLevel.Error, message, exception);
+ Log(LoggingLevel.Error, message, exception);
}
- public void Error(LogOutputProvider messageProvider)
+ public void Error(LogWriterOutputProvider messageProvider)
{
if (!IsErrorEnabled)
return;
object obj = messageProvider();
- LogInternal(LogLevel.Error, obj, null);
+ LogInternal(LoggingLevel.Error, obj, null);
}
/// <summary>
@@ -292,7 +292,7 @@ public void ErrorFormat(string format, params object[] args)
{
if (!IsErrorEnabled)
return;
- LogInternal(LogLevel.Error, string.Format(CultureInfo.CurrentCulture, format, args), null);
+ LogInternal(LoggingLevel.Error, string.Format(CultureInfo.CurrentCulture, format, args), null);
}
/// <summary>
@@ -306,7 +306,7 @@ public void ErrorFormat(IFormatProvider formatProvider, string format, params ob
{
if (!IsErrorEnabled)
return;
- LogInternal(LogLevel.Error, string.Format(formatProvider, format, args), null);
+ LogInternal(LoggingLevel.Error, string.Format(formatProvider, format, args), null);
}
/// <summary>
@@ -318,7 +318,7 @@ public void Fatal(object message)
{
if (!IsFatalEnabled)
return;
- Log(LogLevel.Fatal, message, null);
+ Log(LoggingLevel.Fatal, message, null);
}
/// <summary>
@@ -331,17 +331,17 @@ public void Fatal(object message, Exception exception)
{
if (!IsFatalEnabled)
return;
- Log(LogLevel.Fatal, message, exception);
+ Log(LoggingLevel.Fatal, message, exception);
}
- public void Fatal(LogOutputProvider messageProvider)
+ public void Fatal(LogWriterOutputProvider messageProvider)
{
if (!IsFatalEnabled)
return;
object obj = messageProvider();
- LogInternal(LogLevel.Fatal, obj, null);
+ LogInternal(LoggingLevel.Fatal, obj, null);
}
/// <summary>
@@ -354,7 +354,7 @@ public void FatalFormat(string format, params object[] args)
{
if (!IsFatalEnabled)
return;
- LogInternal(LogLevel.Fatal, string.Format(CultureInfo.CurrentCulture, format, args), null);
+ LogInternal(LoggingLevel.Fatal, string.Format(CultureInfo.CurrentCulture, format, args), null);
}
/// <summary>
@@ -368,10 +368,10 @@ public void FatalFormat(IFormatProvider formatProvider, string format, params ob
{
if (!IsFatalEnabled)
return;
- LogInternal(LogLevel.Fatal, string.Format(formatProvider, format, args), null);
+ LogInternal(LoggingLevel.Fatal, string.Format(formatProvider, format, args), null);
}
- public void Log(LogLevel level, object obj)
+ public void Log(LoggingLevel level, object obj)
{
if (_level < level)
return;
@@ -379,7 +379,7 @@ public void Log(LogLevel level, object obj)
LogInternal(level, obj, null);
}
- public void Log(LogLevel level, object obj, Exception exception)
+ public void Log(LoggingLevel level, object obj, Exception exception)
{
if (_level < level)
return;
@@ -387,7 +387,7 @@ public void Log(LogLevel level, object obj, Exception exception)
LogInternal(level, obj, exception);
}
- public void Log(LogLevel level, LogOutputProvider messageProvider)
+ public void Log(LoggingLevel level, LogWriterOutputProvider messageProvider)
{
if (_level < level)
return;
@@ -397,7 +397,7 @@ public void Log(LogLevel level, LogOutputProvider messageProvider)
LogInternal(level, obj, null);
}
- public void LogFormat(LogLevel level, IFormatProvider formatProvider, string format, params object[] args)
+ public void LogFormat(LoggingLevel level, IFormatProvider formatProvider, string format, params object[] args)
{
if (_level < level)
return;
@@ -416,7 +416,7 @@ public void DebugFormat(Exception exception, string format, params object[] args
{
if (!IsDebugEnabled)
return;
- LogInternal(LogLevel.Debug, string.Format(CultureInfo.CurrentCulture, format, args), exception);
+ LogInternal(LoggingLevel.Debug, string.Format(CultureInfo.CurrentCulture, format, args), exception);
}
/// <summary>
@@ -431,7 +431,7 @@ public void DebugFormat(Exception exception, IFormatProvider formatProvider, str
{
if (!IsDebugEnabled)
return;
- LogInternal(LogLevel.Debug, string.Format(formatProvider, format, args), exception);
+ LogInternal(LoggingLevel.Debug, string.Format(formatProvider, format, args), exception);
}
/// <summary>
@@ -445,7 +445,7 @@ public void InfoFormat(Exception exception, string format, params object[] args)
{
if (!IsInfoEnabled)
return;
- LogInternal(LogLevel.Info, string.Format(CultureInfo.CurrentCulture, format, args), exception);
+ LogInternal(LoggingLevel.Info, string.Format(CultureInfo.CurrentCulture, format, args), exception);
}
/// <summary>
@@ -460,7 +460,7 @@ public void InfoFormat(Exception exception, IFormatProvider formatProvider, stri
{
if (!IsInfoEnabled)
return;
- LogInternal(LogLevel.Info, string.Format(formatProvider, format, args), exception);
+ LogInternal(LoggingLevel.Info, string.Format(formatProvider, format, args), exception);
}
/// <summary>
@@ -474,7 +474,7 @@ public void WarnFormat(Exception exception, string format, params object[] args)
{
if (!IsWarnEnabled)
return;
- LogInternal(LogLevel.Warn, string.Format(CultureInfo.CurrentCulture, format, args), exception);
+ LogInternal(LoggingLevel.Warn, string.Format(CultureInfo.CurrentCulture, format, args), exception);
}
/// <summary>
@@ -489,7 +489,7 @@ public void WarnFormat(Exception exception, IFormatProvider formatProvider, stri
{
if (!IsWarnEnabled)
return;
- LogInternal(LogLevel.Warn, string.Format(formatProvider, format, args), exception);
+ LogInternal(LoggingLevel.Warn, string.Format(formatProvider, format, args), exception);
}
/// <summary>
@@ -503,7 +503,7 @@ public void ErrorFormat(Exception exception, string format, params object[] args
{
if (!IsErrorEnabled)
return;
- LogInternal(LogLevel.Error, string.Format(CultureInfo.CurrentCulture, format, args), exception);
+ LogInternal(LoggingLevel.Error, string.Format(CultureInfo.CurrentCulture, format, args), exception);
}
/// <summary>
@@ -518,7 +518,7 @@ public void ErrorFormat(Exception exception, IFormatProvider formatProvider, str
{
if (!IsErrorEnabled)
return;
- LogInternal(LogLevel.Error, string.Format(formatProvider, format, args), exception);
+ LogInternal(LoggingLevel.Error, string.Format(formatProvider, format, args), exception);
}
/// <summary>
@@ -532,7 +532,7 @@ public void FatalFormat(Exception exception, string format, params object[] args
{
if (!IsFatalEnabled)
return;
- LogInternal(LogLevel.Fatal, string.Format(CultureInfo.CurrentCulture, format, args), exception);
+ LogInternal(LoggingLevel.Fatal, string.Format(CultureInfo.CurrentCulture, format, args), exception);
}
/// <summary>
@@ -547,10 +547,10 @@ public void FatalFormat(Exception exception, IFormatProvider formatProvider, str
{
if (!IsFatalEnabled)
return;
- LogInternal(