Skip to content

Commit

Permalink
Added logging integrations, verified service behavior under control
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Aug 26, 2012
1 parent f70d297 commit 0c3f563
Show file tree
Hide file tree
Showing 45 changed files with 1,193 additions and 441 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:patch: 0
:special: prerelease
:special: ""
:major: 3
:minor: 0
62 changes: 53 additions & 9 deletions rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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" } ).
Expand Down
6 changes: 0 additions & 6 deletions src/.nuget/NuGet.Config

This file was deleted.

139 changes: 0 additions & 139 deletions src/.nuget/NuGet.targets

This file was deleted.

Binary file removed src/.nuget/nuget.exe
Binary file not shown.
4 changes: 0 additions & 4 deletions src/.nuget/packages.config

This file was deleted.

10 changes: 9 additions & 1 deletion src/SampleTopshelfService/SampleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/SolutionVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

[assembly: ComVisibleAttribute(false)]
[assembly: CLSCompliantAttribute(true)]
[assembly: AssemblyInformationalVersion("3.0.0-prerelease.251b83")]
[assembly: AssemblyInformationalVersion("3.0.0.f70d29")]

54 changes: 54 additions & 0 deletions src/Topshelf.Log4Net/Log4NetConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Loading

0 comments on commit 0c3f563

Please sign in to comment.