Skip to content

Commit

Permalink
Moved Serilog.Sinks.DiagnosticTrace to new project
Browse files Browse the repository at this point in the history
  • Loading branch information
merbla committed Jan 21, 2016
1 parent d208a3f commit 413d81b
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 31 deletions.
7 changes: 7 additions & 0 deletions Serilog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Console", "sr
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{9EC69873-5A97-4C25-AB5A-31DDE589B2D9}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.DiagnosticTrace", "src\Serilog.Sinks.DiagnosticTrace\Serilog.Sinks.DiagnosticTrace.xproj", "{8849C92D-2120-4C82-8226-22DF40195237}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -43,6 +45,10 @@ Global
{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
{8849C92D-2120-4C82-8226-22DF40195237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8849C92D-2120-4C82-8226-22DF40195237}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8849C92D-2120-4C82-8226-22DF40195237}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8849C92D-2120-4C82-8226-22DF40195237}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -52,5 +58,6 @@ Global
{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}
{8849C92D-2120-4C82-8226-22DF40195237} = {9EC69873-5A97-4C25-AB5A-31DDE589B2D9}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2013-2016 Serilog Contributors
//
// 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.


using System;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Sinks.DiagnosticTrace;

namespace Serilog
{
public static class DiagnosticTraceConfigurationExtensions
{
/// <summary>
/// Write log events to the <see cref="System.Diagnostics.Trace"/>.
/// </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 Trace(
this LoggerSinkConfiguration sinkConfiguration,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = LoggerConfigurationFullNetFxExtensions.DefaultOutputTemplate,
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 DiagnosticTraceSink(formatter), restrictedToMinimumLevel, levelSwitch);
}
}
}
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>8849c92d-2120-4c82-8226-22df40195237</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.DiagnosticTrace/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.Diagnostics.TraceSource": "4.0.0-beta-23516"
}
}
}
}
31 changes: 3 additions & 28 deletions src/Serilog/LoggerConfigurationFullNetFxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Serilog.Events;
using Serilog.Formatting.Display;
using Serilog.Formatting.Raw;
using Serilog.Sinks.DiagnosticTrace;
using Serilog.Sinks.SystemConsole;

#if PROCESS
Expand All @@ -45,7 +44,8 @@ namespace Serilog
/// </summary>
public static class LoggerConfigurationFullNetFxExtensions
{
const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
//TODO: Need to confirm this is the best location for this default. Used in File, Trace, RollingFike
public const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}";
const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}";
const long DefaultFileSizeLimitBytes = 1L * 1024 * 1024 * 1024;
const int DefaultRetainedFileCountLimit = 31; // A long month of logs
Expand Down Expand Up @@ -182,32 +182,7 @@ public static LoggerConfiguration RollingFile(
return sinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);
}
#endif

/// <summary>
/// Write log events to the <see cref="System.Diagnostics.Trace"/>.
/// </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 Trace(
this LoggerSinkConfiguration sinkConfiguration,
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
string outputTemplate = DefaultOutputTemplate,
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 DiagnosticTraceSink(formatter), restrictedToMinimumLevel, levelSwitch);
}


#if LOGCONTEXT
/// <summary>
/// Enrich log events with properties from <see cref="Context.LogContext"/>.
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,13 +71,12 @@ public void FindsConfigurationMethodsWithinAnAssembly()
.Distinct()
.ToList();

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

Assert.True(configurationMethods.Contains("ColoredConsole"));
Assert.True(configurationMethods.Contains("DumpFile"));
Assert.True(configurationMethods.Contains("File"));
Assert.True(configurationMethods.Contains("RollingFile"));
Assert.True(configurationMethods.Contains("Trace"));
}

[Fact]
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 @@ -11,7 +11,8 @@
"xunit": "2.1.0",
"xunit.runner.visualstudio": "2.1.0",
"xunit.runner.dnx": "2.1.0-rc1-build204",
"Serilog.Sinks.Console": { "target": "project" }
"Serilog.Sinks.Console": { "target": "project" },
"Serilog.Sinks.DiagnosticTrace": { "target": "project" }
},
"frameworks": {
"dnx451": {
Expand Down

0 comments on commit 413d81b

Please sign in to comment.