Skip to content

Commit aea8738

Browse files
authored
Merge pull request #11 from serilog/dev
3.0.0 Release
2 parents 2a0f0df + 3d6a490 commit aea8738

Some content is hidden

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

51 files changed

+2912
-190
lines changed

Build.ps1

+22-7
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

CHANGES.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
2.0.0
2-
- Moved to new project
3-
- DotNet Core support
1+
See: https://github.com/serilog/serilog-sinks-console/releases

README.md

+132-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,146 @@
1-
# Serilog.Sinks.Console
1+
# Serilog.Sinks.Console [![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.Console.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.Console/) [![Documentation](https://img.shields.io/badge/docs-wiki-yellow.svg)](https://github.com/serilog/serilog/wiki) [![Join the chat at https://gitter.im/serilog/serilog](https://img.shields.io/gitter/room/serilog/serilog.svg)](https://gitter.im/serilog/serilog) [![Help](https://img.shields.io/badge/stackoverflow-serilog-orange.svg)](http://stackoverflow.com/questions/tagged/serilog)
22

3-
The console sink for Serilog.
4-
5-
[![Build status](https://ci.appveyor.com/api/projects/status/w1w3m1wyk3in1c96/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-console/branch/master) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.Console.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.Console/)
3+
A Serilog sink that writes log events to the Windows Console or an ANSI terminal via standard output. Coloring and custom themes are supported, including ANSI 256-color themes on macOS, Linux and Windows 10. The default output is plain text; JSON formatting can be plugged in using a package such as [_Serilog.Formatting.Compact_](https://github.com/serilog/serilog-formatting-compact).
64

7-
Writes to the system console. The colored console sink's boring cousin.
5+
### Getting started
86

9-
To use the console sink, first install the NuGet package:
7+
To use the console sink, first install the [NuGet package](https://nuget.org/packages/serilog.sinks.console):
108

119
```powershell
1210
Install-Package Serilog.Sinks.Console
1311
```
1412

13+
Then enable the sink using `WriteTo.Console()`:
14+
1515
```csharp
16-
var log = new LoggerConfiguration()
16+
Log.Logger = new LoggerConfiguration()
1717
.WriteTo.Console()
1818
.CreateLogger();
19+
20+
Log.Information("Hello, world!");
21+
```
22+
23+
Log events will be printed to `STDOUT`:
24+
25+
```
26+
[12:50:51 INF] Hello, world!
27+
```
28+
29+
### Themes
30+
31+
The sink will colorize output by default:
32+
33+
![Colorized Console](https://raw.githubusercontent.com/serilog/serilog-sinks-console/dev/assets/Screenshot.png)
34+
35+
Themes can be specified when configuring the sink:
36+
37+
```csharp
38+
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
39+
```
40+
41+
The following built-in themes are available:
42+
43+
* `ConsoleTheme.None` - no styling
44+
* `SystemConsoleTheme.Literate` - styled to replicate _Serilog.Sinks.Literate_, using the `System.Console` coloring modes supported on all Windows/.NET targets; **this is the default when no theme is specified**
45+
* `SystemConsoleTheme.Grayscale` - a theme using only shades of gray, white, and black
46+
* `AnsiConsoleTheme.Literate` - an ANSI 16-color version of the "literate" theme; we expect to update this to use 256-colors for a more refined look in future
47+
* `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme
48+
* `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme
49+
50+
Adding a new theme is straightforward; examples can be found in the [`SystemConsoleThemes`](https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/SystemConsoleThemes.cs) and [`AnsiConsoleThemes`](https://github.com/serilog/serilog-sinks-console/blob/dev/src/Serilog.Sinks.Console/Sinks/SystemConsole/Themes/AnsiConsoleThemes.cs) classes.
51+
52+
### Output templates
53+
54+
The format of events to the console can be modified using the `outputTemplate` configuration parameter:
55+
56+
```csharp
57+
.WriteTo.Console(
58+
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
59+
```
60+
61+
The default template, shown in the example above, uses built-in properties like `Timestamp` and `Level`. Properties from events, including those attached using [enrichers](https://github.com/serilog/serilog/wiki/Enrichment), can also appear in the output template.
62+
63+
### JSON output
64+
65+
The sink can write JSON output instead of plain text. `CompactJsonFormatter` or `RenderedCompactJsonFormatter` from [Serilog.Formatting.Compact](https://github.com/serilog/serilog-formatting-compact) is recommended:
66+
67+
```powershell
68+
Install-Package Serilog.Formatting.Compact
69+
```
70+
71+
Pass a formatter to the `Console()` configuration method:
72+
73+
```csharp
74+
.WriteTo.Console(new CompactJsonFormatter())
75+
```
76+
77+
Output theming is not available when custom formatters are used.
78+
79+
### XML `<appSettings>` configuration
80+
81+
To use the console sink with the [Serilog.Settings.AppSettings](https://github.com/serilog/serilog-settings-appsettings) package, first install that package if you haven't already done so:
82+
83+
```powershell
84+
Install-Package Serilog.Settings.AppSettings
85+
```
86+
87+
Instead of configuring the logger in code, call `ReadFrom.AppSettings()`:
88+
89+
```csharp
90+
var log = new LoggerConfiguration()
91+
.ReadFrom.AppSettings()
92+
.CreateLogger();
93+
```
94+
95+
In your application's `App.config` or `Web.config` file, specify the console sink assembly under the `<appSettings>` node:
96+
97+
```xml
98+
<configuration>
99+
<appSettings>
100+
<add key="serilog:using:Console" value="Serilog.Sinks.Console" />
101+
<add key="serilog:write-to:Console" />
102+
```
103+
104+
### JSON `appsettings.json` configuration
105+
106+
To use the console sink with _Microsoft.Extensions.Configuration_, for example with ASP.NET Core or .NET Core, use the [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) package. First install that package if you have not already done so:
107+
108+
```powershell
109+
Install-Package Serilog.Settings.Configuration
110+
```
111+
112+
Instead of configuring the sink directly in code, call `ReadFrom.Configuration()`:
113+
114+
```csharp
115+
var configuration = new ConfigurationBuilder()
116+
.AddJsonFile("appsettings.json")
117+
.Build();
118+
119+
var logger = new LoggerConfiguration()
120+
.ReadFrom.Configuration(configuration)
121+
.CreateLogger();
122+
```
123+
124+
In your `appsettings.json` file, under the `Serilog` node, :
125+
126+
```json
127+
{
128+
"Serilog": {
129+
"WriteTo": [{"Name": "Console"}]
130+
}
131+
}
132+
```
133+
134+
### Upgrading from _Serilog.Sinks.Console_ 2.x
135+
136+
To achieve output identical to version 2 of this sink, specify a formatter and output template explicitly:
137+
138+
```csharp
139+
.WriteTo.Console(new MessageTemplateTextFormatter(
140+
"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}",
141+
null))
19142
```
20143

21-
* [Documentation](https://github.com/serilog/serilog/wiki)
144+
This will bypass theming and use Serilog's built-in message template formatting.
22145

23-
Copyright &copy; 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html).
146+
_Copyright &copy; 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._

appveyor.yml

+2-8
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:

assets/Screenshot.png

26 KB
Loading

global.json

-6
This file was deleted.

sample/ConsoleDemo/ConsoleDemo.csproj

+12
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

+40
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

+19-6
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

0 commit comments

Comments
 (0)