-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from serilog/dev
3.0.0 Release
- Loading branch information
Showing
51 changed files
with
2,912 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,44 @@ | ||
echo "build: Build started" | ||
|
||
Push-Location $PSScriptRoot | ||
|
||
if(Test-Path .\artifacts) { Remove-Item .\artifacts -Force -Recurse } | ||
if(Test-Path .\artifacts) { | ||
echo "build: Cleaning .\artifacts" | ||
Remove-Item .\artifacts -Force -Recurse | ||
} | ||
|
||
& dotnet restore --no-cache | ||
|
||
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; | ||
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; | ||
$suffix = @{ $true = ""; $false = "$branch-$revision"}[$branch -eq "master" -and $revision -ne "local"] | ||
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] | ||
$commitHash = $(git rev-parse --short HEAD) | ||
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] | ||
|
||
echo "build: Package version suffix is $suffix" | ||
echo "build: Build version suffix is $buildSuffix" | ||
|
||
foreach ($src in ls src/Serilog.*) { | ||
foreach ($src in ls src/*) { | ||
Push-Location $src | ||
|
||
& dotnet pack -c Release -o ..\..\.\artifacts --version-suffix=$suffix | ||
echo "build: Packaging project in $src" | ||
|
||
& dotnet build -c Release --version-suffix=$buildSuffix | ||
& dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build | ||
if($LASTEXITCODE -ne 0) { exit 1 } | ||
|
||
Pop-Location | ||
} | ||
|
||
foreach ($test in ls test/Serilog.*.Tests) { | ||
foreach ($test in ls test/*.Tests) { | ||
Push-Location $test | ||
|
||
echo "build: Testing project in $test" | ||
|
||
& dotnet test -c Release | ||
if($LASTEXITCODE -ne 0) { exit 2 } | ||
if($LASTEXITCODE -ne 0) { exit 3 } | ||
|
||
Pop-Location | ||
} | ||
|
||
Pop-Location | ||
Pop-Location |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
2.0.0 | ||
- Moved to new project | ||
- DotNet Core support | ||
See: https://github.com/serilog/serilog-sinks-console/releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,146 @@ | ||
# Serilog.Sinks.Console | ||
# 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) | ||
|
||
The console sink for Serilog. | ||
|
||
[![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/) | ||
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). | ||
|
||
Writes to the system console. The colored console sink's boring cousin. | ||
### Getting started | ||
|
||
To use the console sink, first install the NuGet package: | ||
To use the console sink, first install the [NuGet package](https://nuget.org/packages/serilog.sinks.console): | ||
|
||
```powershell | ||
Install-Package Serilog.Sinks.Console | ||
``` | ||
|
||
Then enable the sink using `WriteTo.Console()`: | ||
|
||
```csharp | ||
var log = new LoggerConfiguration() | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
Log.Information("Hello, world!"); | ||
``` | ||
|
||
Log events will be printed to `STDOUT`: | ||
|
||
``` | ||
[12:50:51 INF] Hello, world! | ||
``` | ||
|
||
### Themes | ||
|
||
The sink will colorize output by default: | ||
|
||
![Colorized Console](https://raw.githubusercontent.com/serilog/serilog-sinks-console/dev/assets/Screenshot.png) | ||
|
||
Themes can be specified when configuring the sink: | ||
|
||
```csharp | ||
.WriteTo.Console(theme: AnsiConsoleTheme.Code) | ||
``` | ||
|
||
The following built-in themes are available: | ||
|
||
* `ConsoleTheme.None` - no styling | ||
* `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** | ||
* `SystemConsoleTheme.Grayscale` - a theme using only shades of gray, white, and black | ||
* `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 | ||
* `AnsiConsoleTheme.Grayscale` - an ANSI 256-color version of the "grayscale" theme | ||
* `AnsiConsoleTheme.Code` - an ANSI 256-color Visual Studio Code-inspired theme | ||
|
||
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. | ||
|
||
### Output templates | ||
|
||
The format of events to the console can be modified using the `outputTemplate` configuration parameter: | ||
|
||
```csharp | ||
.WriteTo.Console( | ||
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}") | ||
``` | ||
|
||
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. | ||
|
||
### JSON output | ||
|
||
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: | ||
|
||
```powershell | ||
Install-Package Serilog.Formatting.Compact | ||
``` | ||
|
||
Pass a formatter to the `Console()` configuration method: | ||
|
||
```csharp | ||
.WriteTo.Console(new CompactJsonFormatter()) | ||
``` | ||
|
||
Output theming is not available when custom formatters are used. | ||
|
||
### XML `<appSettings>` configuration | ||
|
||
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: | ||
|
||
```powershell | ||
Install-Package Serilog.Settings.AppSettings | ||
``` | ||
|
||
Instead of configuring the logger in code, call `ReadFrom.AppSettings()`: | ||
|
||
```csharp | ||
var log = new LoggerConfiguration() | ||
.ReadFrom.AppSettings() | ||
.CreateLogger(); | ||
``` | ||
|
||
In your application's `App.config` or `Web.config` file, specify the console sink assembly under the `<appSettings>` node: | ||
|
||
```xml | ||
<configuration> | ||
<appSettings> | ||
<add key="serilog:using:Console" value="Serilog.Sinks.Console" /> | ||
<add key="serilog:write-to:Console" /> | ||
``` | ||
|
||
### JSON `appsettings.json` configuration | ||
|
||
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: | ||
|
||
```powershell | ||
Install-Package Serilog.Settings.Configuration | ||
``` | ||
|
||
Instead of configuring the sink directly in code, call `ReadFrom.Configuration()`: | ||
|
||
```csharp | ||
var configuration = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.Build(); | ||
|
||
var logger = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.CreateLogger(); | ||
``` | ||
|
||
In your `appsettings.json` file, under the `Serilog` node, : | ||
|
||
```json | ||
{ | ||
"Serilog": { | ||
"WriteTo": [{"Name": "Console"}] | ||
} | ||
} | ||
``` | ||
|
||
### Upgrading from _Serilog.Sinks.Console_ 2.x | ||
|
||
To achieve output identical to version 2 of this sink, specify a formatter and output template explicitly: | ||
|
||
```csharp | ||
.WriteTo.Console(new MessageTemplateTextFormatter( | ||
"{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}", | ||
null)) | ||
``` | ||
|
||
* [Documentation](https://github.com/serilog/serilog/wiki) | ||
This will bypass theming and use Serilog's built-in message template formatting. | ||
|
||
Copyright © 2016 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html). | ||
_Copyright © 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>netcoreapp1.1;net45</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Serilog.Sinks.Console\Serilog.Sinks.Console.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Serilog; | ||
using System; | ||
using System.Threading; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
|
||
namespace ConsoleDemo | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.Console(theme: AnsiConsoleTheme.Code) | ||
.CreateLogger(); | ||
|
||
try | ||
{ | ||
Log.Debug("Getting started"); | ||
|
||
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId); | ||
|
||
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 }); | ||
|
||
Fail(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Error(e, "Something went wrong"); | ||
} | ||
|
||
Log.CloseAndFlush(); | ||
} | ||
|
||
static void Fail() | ||
{ | ||
throw new DivideByZeroException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.