Skip to content

Commit

Permalink
Merge pull request serilog#630 from merbla/packagefactoring-sinks
Browse files Browse the repository at this point in the history
Package Refactoring - Split Console Sink to new project
  • Loading branch information
nblumhardt committed Jan 14, 2016
2 parents 0b7aba9 + d6b322c commit b195b43
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 28 deletions.
10 changes: 10 additions & 0 deletions Serilog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog", "src\Serilog\Seri
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Tests", "test\Serilog.Tests\Serilog.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Console", "src\Serilog.Sinks.Console\Serilog.Sinks.Console.xproj", "{866A028E-27DB-49A0-AC78-E5FEF247C099}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{9EC69873-5A97-4C25-AB5A-31DDE589B2D9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -35,12 +39,18 @@ Global
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU
{866A028E-27DB-49A0-AC78-E5FEF247C099}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{866A028E-27DB-49A0-AC78-E5FEF247C099}.Debug|Any CPU.Build.0 = Debug|Any CPU
{866A028E-27DB-49A0-AC78-E5FEF247C099}.Release|Any CPU.ActiveCfg = Release|Any CPU
{866A028E-27DB-49A0-AC78-E5FEF247C099}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{803CD13A-D54B-4CEC-A55F-E22AE3D93B3C} = {037440DE-440B-4129-9F7A-09B42D00397E}
{3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {0D135C0C-A60B-454A-A2F4-CD74A30E04B0}
{866A028E-27DB-49A0-AC78-E5FEF247C099} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{9EC69873-5A97-4C25-AB5A-31DDE589B2D9} = {037440DE-440B-4129-9F7A-09B42D00397E}
EndGlobalSection
EndGlobal
39 changes: 39 additions & 0 deletions src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Sinks.SystemConsole;

namespace Serilog
{
public static class ConsoleLoggerConfigurationExtensions
{
const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}";

/// <summary>
/// Writes log events to <see cref="System.Console"/>.
/// </summary>
/// <param name="sinkConfiguration">Logger sink configuration.</param>
/// <param name="restrictedToMinimumLevel">The minimum level for
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
/// to be changed at runtime.</param>
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <returns>Configuration object allowing method chaining.</returns>
public static LoggerConfiguration Console(
this LoggerSinkConfiguration sinkConfiguration,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = DefaultConsoleOutputTemplate,
IFormatProvider formatProvider = null,
LoggingLevelSwitch levelSwitch = null)
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
return sinkConfiguration.Sink(new ConsoleSink(formatter), restrictedToMinimumLevel, levelSwitch);
}
}
}
18 changes: 18 additions & 0 deletions src/Serilog.Sinks.Console/Serilog.Sinks.Console.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>866a028e-27db-49a0-ac78-e5fef247c099</ProjectGuid>
<RootNamespace>Serilog</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
24 changes: 24 additions & 0 deletions src/Serilog.Sinks.Console/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "2.0.0-beta-*",
"description": "The console sink for Serilog - Simple .NET logging with fully-structured events",
"authors": [ "Serilog Contributors" ],
"tags": [ "serilog", "console" ],
"projectUrl": "http://serilog.net",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0",
"iconUrl": "http://serilog.net/images/serilog-sink-nuget.png",
"dependencies": {
"Serilog": { "target": "project" }
},
"compilationOptions": {
"keyFile": "../../assets/Serilog.snk"
},
"frameworks": {
"net45": {
},
"dotnet5.1": {
"dependencies": {
"System.Console": "4.0.0-beta-23516"
}
}
}
}
24 changes: 0 additions & 24 deletions src/Serilog/LoggerConfigurationFullNetFxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,6 @@ public static class LoggerConfigurationFullNetFxExtensions
const long DefaultFileSizeLimitBytes = 1L * 1024 * 1024 * 1024;
const int DefaultRetainedFileCountLimit = 31; // A long month of logs

/// <summary>
/// Writes log events to <see cref="System.Console"/>.
/// </summary>
/// <param name="sinkConfiguration">Logger sink configuration.</param>
/// <param name="restrictedToMinimumLevel">The minimum level for
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
/// to be changed at runtime.</param>
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <returns>Configuration object allowing method chaining.</returns>
public static LoggerConfiguration Console(
this LoggerSinkConfiguration sinkConfiguration,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = DefaultConsoleOutputTemplate,
IFormatProvider formatProvider = null,
LoggingLevelSwitch levelSwitch = null)
{
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
return sinkConfiguration.Sink(new ConsoleSink(formatter), restrictedToMinimumLevel, levelSwitch);
}

/// <summary>
/// Writes log events to <see cref="System.Console"/>, using color to differentiate
Expand Down
3 changes: 1 addition & 2 deletions test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ public void FindsConfigurationMethodsWithinAnAssembly()
.Distinct()
.ToList();

Assert.Equal(6, configurationMethods.Count);
Assert.Equal(5, configurationMethods.Count);

Assert.True(configurationMethods.Contains("ColoredConsole"));
Assert.True(configurationMethods.Contains("Console"));
Assert.True(configurationMethods.Contains("DumpFile"));
Assert.True(configurationMethods.Contains("File"));
Assert.True(configurationMethods.Contains("RollingFile"));
Expand Down
5 changes: 3 additions & 2 deletions test/Serilog.Tests/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"version": "2.0.0-beta-*",
"commands": {
"test": "xunit.runner.dnx",
Expand All @@ -10,7 +10,8 @@
"Serilog": { "target": "project" },
"xunit": "2.1.0",
"xunit.runner.visualstudio": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204"
"xunit.runner.dnx": "2.1.0-rc1-build204",
"Serilog.Sinks.Console": { "target": "project" }
},
"frameworks": {
"dnx451": {
Expand Down

0 comments on commit b195b43

Please sign in to comment.