Skip to content

Commit c961117

Browse files
authored
Merge pull request #8 from nblumhardt/great-console-unification
Grand Unified Console [WIP]
2 parents 29e5d58 + 5969acc commit c961117

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2773
-189
lines changed

Build.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
1+
echo "build: Build started"
2+
13
Push-Location $PSScriptRoot
24

3-
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse }
5+
if(Test-Path .\artifacts) {
6+
echo "build: Cleaning .\artifacts"
7+
Remove-Item .\artifacts -Force -Recurse
8+
}
49

510
& dotnet restore --no-cache
611

712
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
813
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
9-
$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "master" -and $revision -ne "local"]
14+
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"]
15+
$commitHash = $(git rev-parse --short HEAD)
16+
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]
17+
18+
echo "build: Package version suffix is $suffix"
19+
echo "build: Build version suffix is $buildSuffix"
1020

11-
foreach ($src in ls src/Serilog.*) {
21+
foreach ($src in ls src/*) {
1222
Push-Location $src
1323

14-
& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$suffix
24+
echo "build: Packaging project in $src"
25+
26+
& dotnet build -c Release --version-suffix=$buildSuffix
27+
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build
1528
if($LASTEXITCODE -ne 0) { exit 1 }
1629

1730
Pop-Location
1831
}
1932

20-
foreach ($test in ls test/Serilog.*.Tests) {
33+
foreach ($test in ls test/*.Tests) {
2134
Push-Location $test
2235

36+
echo "build: Testing project in $test"
37+
2338
& dotnet test -c Release
24-
if($LASTEXITCODE -ne 0) { exit 2 }
39+
if($LASTEXITCODE -ne 0) { exit 3 }
2540

2641
Pop-Location
2742
}
2843

29-
Pop-Location
44+
Pop-Location

appveyor.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2015
3+
image: Visual Studio 2017
44
configuration: Release
5-
install:
6-
- ps: mkdir -Force ".\build\" | Out-Null
7-
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
8-
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
9-
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121'
10-
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
5+
test: off
116
build_script:
127
- ps: ./Build.ps1
13-
test: off
148
artifacts:
159
- path: artifacts/Serilog.*.nupkg
1610
deploy:

global.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFrameworks>netcoreapp1.1;net45</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Serilog.Sinks.Console\Serilog.Sinks.Console.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

sample/ConsoleDemo/Program.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Serilog;
2+
using System;
3+
using System.Threading;
4+
using Serilog.Sinks.SystemConsole.Themes;
5+
6+
namespace ConsoleDemo
7+
{
8+
public class Program
9+
{
10+
public static void Main()
11+
{
12+
Log.Logger = new LoggerConfiguration()
13+
.MinimumLevel.Verbose()
14+
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
15+
.CreateLogger();
16+
17+
try
18+
{
19+
Log.Debug("Getting started");
20+
21+
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
22+
23+
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
24+
25+
Fail();
26+
}
27+
catch (Exception e)
28+
{
29+
Log.Error(e, "Something went wrong");
30+
}
31+
32+
Log.CloseAndFlush();
33+
}
34+
35+
static void Fail()
36+
{
37+
throw new DivideByZeroException();
38+
}
39+
}
40+
}

serilog-sinks-console.sln

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26430.12
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
99
ProjectSection(SolutionItems) = preProject
10+
.gitattributes = .gitattributes
11+
.gitignore = .gitignore
12+
appveyor.yml = appveyor.yml
1013
Build.ps1 = Build.ps1
11-
global.json = global.json
14+
CHANGES.md = CHANGES.md
15+
LICENSE = LICENSE
1216
NuGet.Config = NuGet.Config
1317
README.md = README.md
1418
assets\Serilog.snk = assets\Serilog.snk
1519
EndProjectSection
1620
EndProject
17-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Console", "src\Serilog.Sinks.Console\Serilog.Sinks.Console.xproj", "{866A028E-27DB-49A0-AC78-E5FEF247C099}"
18-
EndProject
1921
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}"
2022
EndProject
21-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Console.Tests", "test\Serilog.Sinks.Console.Tests\Serilog.Sinks.Console.Tests.xproj", "{1D56534C-4009-42C2-A573-789CAE6B8AA9}"
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Console", "src\Serilog.Sinks.Console\Serilog.Sinks.Console.csproj", "{866A028E-27DB-49A0-AC78-E5FEF247C099}"
24+
EndProject
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Console.Tests", "test\Serilog.Sinks.Console.Tests\Serilog.Sinks.Console.Tests.csproj", "{1D56534C-4009-42C2-A573-789CAE6B8AA9}"
26+
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{CF817664-4CEC-4B6A-9C57-A0D687757D82}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDemo", "sample\ConsoleDemo\ConsoleDemo.csproj", "{DBF4907A-63A2-4895-8DEF-59F90C20380B}"
2230
EndProject
2331
Global
2432
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -34,12 +42,17 @@ Global
3442
{1D56534C-4009-42C2-A573-789CAE6B8AA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
3543
{1D56534C-4009-42C2-A573-789CAE6B8AA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
3644
{1D56534C-4009-42C2-A573-789CAE6B8AA9}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{DBF4907A-63A2-4895-8DEF-59F90C20380B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{DBF4907A-63A2-4895-8DEF-59F90C20380B}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{DBF4907A-63A2-4895-8DEF-59F90C20380B}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{DBF4907A-63A2-4895-8DEF-59F90C20380B}.Release|Any CPU.Build.0 = Release|Any CPU
3749
EndGlobalSection
3850
GlobalSection(SolutionProperties) = preSolution
3951
HideSolutionNode = FALSE
4052
EndGlobalSection
4153
GlobalSection(NestedProjects) = preSolution
4254
{866A028E-27DB-49A0-AC78-E5FEF247C099} = {037440DE-440B-4129-9F7A-09B42D00397E}
4355
{1D56534C-4009-42C2-A573-789CAE6B8AA9} = {7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}
56+
{DBF4907A-63A2-4895-8DEF-59F90C20380B} = {CF817664-4CEC-4B6A-9C57-A0D687757D82}
4457
EndGlobalSection
4558
EndGlobal

src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
using System;
1+
// Copyright 2017 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
216
using Serilog.Configuration;
317
using Serilog.Core;
418
using Serilog.Events;
519
using Serilog.Formatting;
6-
using Serilog.Formatting.Display;
720
using Serilog.Sinks.SystemConsole;
21+
using Serilog.Sinks.SystemConsole.Themes;
22+
using Serilog.Sinks.SystemConsole.Output;
823

924
namespace Serilog
1025
{
@@ -13,7 +28,7 @@ namespace Serilog
1328
/// </summary>
1429
public static class ConsoleLoggerConfigurationExtensions
1530
{
16-
const string DefaultConsoleOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}";
31+
const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
1732

1833
/// <summary>
1934
/// Writes log events to <see cref="System.Console"/>.
@@ -24,22 +39,30 @@ public static class ConsoleLoggerConfigurationExtensions
2439
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
2540
/// to be changed at runtime.</param>
2641
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
27-
/// the default is "{Timestamp} [{Level}] {Message}{NewLine}{Exception}".</param>
42+
/// the default is <code>"[{Timestamp:HH:mm:ss} {Level:u3}] {Message}{NewLine}{Exception}"</code>.</param>
2843
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
2944
/// <param name="standardErrorFromLevel">Specifies the level at which events will be written to standard error.</param>
45+
/// <param name="theme">The theme to apply to the styled output. If not specified,
46+
/// uses <see cref="SystemConsoleTheme.Literate"/>.</param>
3047
/// <returns>Configuration object allowing method chaining.</returns>
3148
public static LoggerConfiguration Console(
3249
this LoggerSinkConfiguration sinkConfiguration,
3350
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
3451
string outputTemplate = DefaultConsoleOutputTemplate,
3552
IFormatProvider formatProvider = null,
3653
LoggingLevelSwitch levelSwitch = null,
37-
LogEventLevel? standardErrorFromLevel = null)
54+
LogEventLevel? standardErrorFromLevel = null,
55+
ConsoleTheme theme = null)
3856
{
3957
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
4058
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
41-
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
42-
return Console(sinkConfiguration, formatter, restrictedToMinimumLevel, levelSwitch, standardErrorFromLevel);
59+
60+
var appliedTheme = System.Console.IsOutputRedirected || System.Console.IsErrorRedirected ?
61+
ConsoleTheme.None :
62+
theme ?? SystemConsoleThemes.Literate;
63+
64+
var formatter = new OutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider);
65+
return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel), restrictedToMinimumLevel, levelSwitch);
4366
}
4467

4568
/// <summary>
@@ -63,7 +86,8 @@ public static LoggerConfiguration Console(
6386
{
6487
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
6588
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
66-
return sinkConfiguration.Sink(new ConsoleSink(formatter, standardErrorFromLevel), restrictedToMinimumLevel, levelSwitch);
89+
90+
return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel), restrictedToMinimumLevel, levelSwitch);
6791
}
6892
}
69-
}
93+
}

src/Serilog.Sinks.Console/Properties/AssemblyInfo.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
using System;
2-
using System.Reflection;
3-
using System.Runtime.CompilerServices;
1+
// Copyright 2017 Serilog Contributors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
414

5-
[assembly: AssemblyVersion("2.0.0.0")]
15+
using System;
16+
using System.Runtime.CompilerServices;
617

718
[assembly: CLSCompliant(true)]
819

9-
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=" +
20+
[assembly: InternalsVisibleTo("Serilog.Sinks.SystemConsole.Tests, PublicKey=" +
1021
"0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c" +
1122
"6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9" +
1223
"d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b818" +
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
5+
<VersionPrefix>3.0.0</VersionPrefix>
6+
<Authors>Serilog Contributors</Authors>
7+
<TargetFrameworks>net45;netstandard1.3;netcoreapp1.1</TargetFrameworks>
8+
<AssemblyName>Serilog.Sinks.Console</AssemblyName>
9+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
10+
<SignAssembly>true</SignAssembly>
11+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
12+
<PackageId>Serilog.Sinks.Console</PackageId>
13+
<PackageTags>serilog;console;terminal</PackageTags>
14+
<PackageIconUrl>http://serilog.net/images/serilog-sink-nuget.png</PackageIconUrl>
15+
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-console</PackageProjectUrl>
16+
<PackageLicenseUrl>https://www.apache.org/licenses/LICENSE-2.0</PackageLicenseUrl>
17+
<GenerateAssemblyVersionAttribute>true</GenerateAssemblyVersionAttribute>
18+
<GenerateAssemblyFileVersionAttribute>true</GenerateAssemblyFileVersionAttribute>
19+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
20+
<!-- Don't reference the full NETStandard.Library -->
21+
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
22+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
23+
<TreatSpecificWarningsAsErrors />
24+
<RootNamespace>Serilog</RootNamespace>
25+
</PropertyGroup>
26+
27+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net45' ">
28+
<DefineConstants>$(DefineConstants);PINVOKE</DefineConstants>
29+
</PropertyGroup>
30+
31+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
32+
<DefineConstants>$(DefineConstants);PINVOKE;RUNTIME_INFORMATION</DefineConstants>
33+
</PropertyGroup>
34+
35+
<ItemGroup>
36+
<PackageReference Include="Serilog" Version="2.5.0-dev-00855" />
37+
</ItemGroup>
38+
39+
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
40+
<Reference Include="System" />
41+
<Reference Include="Microsoft.CSharp" />
42+
</ItemGroup>
43+
44+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
45+
<PackageReference Include="System.Console" Version="4.3.0" />
46+
</ItemGroup>
47+
48+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
49+
<PackageReference Include="System.Console" Version="4.3.0" />
50+
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
51+
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
52+
</ItemGroup>
53+
54+
</Project>

src/Serilog.Sinks.Console/Serilog.Sinks.Console.xproj

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)