Skip to content

Commit

Permalink
Moved IOTextWriter to new sink project
Browse files Browse the repository at this point in the history
  • Loading branch information
merbla committed Jan 21, 2016
1 parent 1c56af8 commit 9f1bad4
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 32 deletions.
7 changes: 7 additions & 0 deletions Serilog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.PeriodicBatch
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Observable", "src\Serilog.Sinks.Observable\Serilog.Sinks.Observable.xproj", "{8D6C0BB9-D04D-49B6-9043-4A776AD275D5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.IOTextWriter", "src\Serilog.Sinks.IOTextWriter\Serilog.Sinks.IOTextWriter.xproj", "{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -79,6 +81,10 @@ Global
{8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D6C0BB9-D04D-49B6-9043-4A776AD275D5}.Release|Any CPU.Build.0 = Release|Any CPU
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -94,5 +100,6 @@ Global
{50B24ACA-D8F0-4268-A477-871B0A92A04A} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{324C2F52-D9F7-4844-9BC4-9906E228D380} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{8D6C0BB9-D04D-49B6-9043-4A776AD275D5} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.IO;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Sinks.IOTextWriter;

namespace Serilog
{
public static class IOTextWriterConfigurationExtensions
{
/// <summary>
/// Write log events to the provided <see cref="TextWriter"/>.
/// </summary>
/// <param name="sinkConfiguration">Logger sink configuration.</param>
/// <param name="textWriter">The text writer to write log events to.</param>
/// <param name="outputTemplate">Message template describing the output format.</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>
/// <returns>Configuration object allowing method chaining.</returns>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <exception cref="ArgumentNullException"></exception>
public static LoggerConfiguration TextWriter(
this LoggerSinkConfiguration sinkConfiguration,
TextWriter textWriter,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = LoggerConfigurationFullNetFxExtensions.DefaultOutputTemplate,
IFormatProvider formatProvider = null,
LoggingLevelSwitch levelSwitch = null)
{
if (textWriter == null) throw new ArgumentNullException(nameof(textWriter));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));

var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
var sink = new TextWriterSink(textWriter, formatter);
return sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);
}
}
}
18 changes: 18 additions & 0 deletions src/Serilog.Sinks.IOTextWriter/Serilog.Sinks.IOTextWriter.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>e85abec7-9b4c-432c-9a04-ac5be9205d9f</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>
29 changes: 29 additions & 0 deletions src/Serilog.Sinks.IOTextWriter/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.0.0-beta-*",
"description": "The IO Text Writer sink for Serilog - Simple .NET logging with fully-structured events",
"authors": [ "Serilog Contributors" ],
"tags": [ "serilog", "IO", "text", "writer"],
"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.IO": "4.0.11-beta-23516"
}
},
"dotnet5.4": {
"dependencies": {
"System.IO": "4.0.11-beta-23516"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
<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>324c2f52-d9f7-4844-9bc4-9906e228d380</ProjectGuid>
<RootNamespace>Serilog.Sinks.PeriodicBatching</RootNamespace>
<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>
</Project>
28 changes: 1 addition & 27 deletions src/Serilog/Configuration/LoggerSinkConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
using Serilog.Core.Sinks;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Sinks.IOTextWriter;
using Serilog.Formatting.Display;

namespace Serilog.Configuration
{
Expand Down Expand Up @@ -109,32 +108,7 @@ public LoggerConfiguration Sink<TSink>(
return Sink(new TSink(), restrictedToMinimumLevel, levelSwitch);
}

/// <summary>
/// Write log events to the provided <see cref="TextWriter"/>.
/// </summary>
/// <param name="textWriter">The text writer to write log events to.</param>
/// <param name="outputTemplate">Message template describing the output format.</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>
/// <returns>Configuration object allowing method chaining.</returns>
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
/// <exception cref="ArgumentNullException"></exception>
public LoggerConfiguration TextWriter(
TextWriter textWriter,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = DefaultOutputTemplate,
IFormatProvider formatProvider = null,
LoggingLevelSwitch levelSwitch = null)
{
if (textWriter == null) throw new ArgumentNullException(nameof(textWriter));
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));

var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
var sink = new TextWriterSink(textWriter, formatter);
return Sink(sink, restrictedToMinimumLevel, levelSwitch);
}

/// <summary>
/// Write log events to a sub-logger, where further processing may occur. Events through
Expand Down
3 changes: 2 additions & 1 deletion test/Serilog.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"Serilog.Sinks.IOFile": { "target": "project" },
"Serilog.Sinks.RollingFile": { "target": "project" },
"Serilog.Sinks.PeriodicBatching": { "target": "project" },
"Serilog.Sinks.Observable": {"target": "project"}
"Serilog.Sinks.Observable": { "target": "project" },
"Serilog.Sinks.IOTextWriter": {"target": "project"}
},
"frameworks": {
"dnx451": {
Expand Down

0 comments on commit 9f1bad4

Please sign in to comment.