Skip to content

Commit 430df84

Browse files
authored
Merge pull request #1 from serilog/dev
1.0.0 Release
2 parents 4c0885f + 144004e commit 430df84

20 files changed

+549
-2
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
root=true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Auto detect text files and perform LF normalization
2+
3+
* text=auto

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: csharp
2+
3+
matrix:
4+
include:
5+
- os: linux # Ubuntu 14.04
6+
dist: trusty
7+
sudo: required
8+
dotnet: 1.0.4
9+
group: edge
10+
11+
script:
12+
- ./build.sh

Build.ps1

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
echo "build: Build started"
2+
3+
Push-Location $PSScriptRoot
4+
5+
if(Test-Path .\artifacts) {
6+
echo "build: Cleaning .\artifacts"
7+
Remove-Item .\artifacts -Force -Recurse
8+
}
9+
10+
& dotnet restore --no-cache
11+
12+
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL];
13+
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
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"
20+
21+
foreach ($src in ls src/*) {
22+
Push-Location $src
23+
24+
echo "build: Packaging project in $src"
25+
26+
& dotnet build -c Release --version-suffix=$buildSuffix
27+
if ($suffix) {
28+
& dotnet pack -c Release --include-source -o ..\..\artifacts --version-suffix=$suffix --no-build
29+
} else {
30+
& dotnet pack -c Release --include-source -o ..\..\artifacts --no-build
31+
}
32+
if($LASTEXITCODE -ne 0) { exit 1 }
33+
34+
Pop-Location
35+
}
36+
37+
foreach ($test in ls test/*.Tests) {
38+
Push-Location $test
39+
40+
echo "build: Testing project in $test"
41+
42+
& dotnet test -c Release
43+
if($LASTEXITCODE -ne 0) { exit 3 }
44+
45+
Pop-Location
46+
}
47+
48+
Pop-Location

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See: https://github.com/serilog/serilog-sinks-debug/releases

README.md

+82-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,82 @@
1-
# serilog-sinks-debug
2-
Writes Serilog events to the debug output window
1+
# Serilog.Sinks.Debug [![Build status](https://ci.appveyor.com/api/projects/status/oufg4e51868oq4eu?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-debug) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Sinks.Debug.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.Debug/) [![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)
2+
3+
A Serilog sink that writes log events to the Visual Studio debug output window.
4+
5+
### Getting started
6+
7+
To use the sink, first install the [NuGet package](https://nuget.org/packages/serilog.sinks.debug):
8+
9+
```powershell
10+
Install-Package Serilog.Sinks.Debug
11+
```
12+
13+
Then enable the sink using `WriteTo.Debug()`:
14+
15+
```csharp
16+
Log.Logger = new LoggerConfiguration()
17+
.WriteTo.Debug()
18+
.CreateLogger();
19+
20+
Log.Information("Hello, world!");
21+
```
22+
23+
Log events will be printed to the debug output:
24+
25+
![Debug Output](https://raw.githubusercontent.com/serilog/serilog-sinks-debug/dev/assets/Screenshot.png)
26+
27+
### XML `<appSettings>` configuration
28+
29+
To use the 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:
30+
31+
```powershell
32+
Install-Package Serilog.Settings.AppSettings
33+
```
34+
35+
Instead of configuring the logger in code, call `ReadFrom.AppSettings()`:
36+
37+
```csharp
38+
var log = new LoggerConfiguration()
39+
.ReadFrom.AppSettings()
40+
.CreateLogger();
41+
```
42+
43+
In your application's `App.config` or `Web.config` file, specify the console sink assembly under the `<appSettings>` node:
44+
45+
```xml
46+
<configuration>
47+
<appSettings>
48+
<add key="serilog:using:Debug" value="Serilog.Sinks.Debug" />
49+
<add key="serilog:write-to:Debug" />
50+
```
51+
52+
### JSON `appsettings.json` configuration
53+
54+
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:
55+
56+
```powershell
57+
Install-Package Serilog.Settings.Configuration
58+
```
59+
60+
Instead of configuring the sink directly in code, call `ReadFrom.Configuration()`:
61+
62+
```csharp
63+
var configuration = new ConfigurationBuilder()
64+
.AddJsonFile("appsettings.json")
65+
.Build();
66+
67+
var logger = new LoggerConfiguration()
68+
.ReadFrom.Configuration(configuration)
69+
.CreateLogger();
70+
```
71+
72+
In your `appsettings.json` file, under the `Serilog` node, :
73+
74+
```json
75+
{
76+
"Serilog": {
77+
"WriteTo": ["Debug"]
78+
}
79+
}
80+
```
81+
82+
_Copyright &copy; 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._

appveyor.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '{build}'
2+
skip_tags: true
3+
image: Visual Studio 2017
4+
configuration: Release
5+
test: off
6+
build_script:
7+
- ps: ./Build.ps1
8+
artifacts:
9+
- path: artifacts/Serilog.*.nupkg
10+
deploy:
11+
- provider: NuGet
12+
api_key:
13+
secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x
14+
skip_symbols: true
15+
on:
16+
branch: /^(master|dev)$/
17+
- provider: GitHub
18+
auth_token:
19+
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
20+
artifact: /Serilog.*\.nupkg/
21+
tag: v$(appveyor_build_version)
22+
on:
23+
branch: master

assets/Screenshot.png

26.6 KB
Loading

assets/Serilog.snk

596 Bytes
Binary file not shown.

build.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -e
4+
dotnet --info
5+
dotnet restore
6+
7+
for path in src/**/*.csproj; do
8+
dotnet build -f netstandard1.0 -c Release ${path}
9+
done
10+
11+
for path in test/*.Tests/*.csproj; do
12+
dotnet test -f netcoreapp2.0 -c Release ${path}
13+
done
14+
15+
for path in sample/**/*.csproj; do
16+
dotnet build -f netcoreapp2.0 -c Release ${path}
17+
done

sample/DebugDemo/DebugDemo.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>netcoreapp2.0</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\Serilog.Sinks.Debug\Serilog.Sinks.Debug.csproj" />
10+
</ItemGroup>
11+
12+
</Project>

sample/DebugDemo/Program.cs

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

serilog-sinks-debug.sln

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26730.10
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5E1-DEB9-4A04-8BAB-24EC7240ADAF}"
9+
ProjectSection(SolutionItems) = preProject
10+
.gitattributes = .gitattributes
11+
.gitignore = .gitignore
12+
appveyor.yml = appveyor.yml
13+
Build.ps1 = Build.ps1
14+
CHANGES.md = CHANGES.md
15+
LICENSE = LICENSE
16+
NuGet.Config = NuGet.Config
17+
README.md = README.md
18+
assets\Serilog.snk = assets\Serilog.snk
19+
EndProjectSection
20+
EndProject
21+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}"
22+
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{CF817664-4CEC-4B6A-9C57-A0D687757D82}"
24+
EndProject
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Debug", "src\Serilog.Sinks.Debug\Serilog.Sinks.Debug.csproj", "{C550B95D-65D5-407A-9DE4-628EA1473D68}"
26+
EndProject
27+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DebugDemo", "sample\DebugDemo\DebugDemo.csproj", "{1756216A-0EC9-42A0-AB0A-B2C01F07698C}"
28+
EndProject
29+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Debug.Tests", "test\Serilog.Sinks.Debug.Tests\Serilog.Sinks.Debug.Tests.csproj", "{0CA08585-BC86-4478-B497-D14FB7FF8FE2}"
30+
EndProject
31+
Global
32+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
33+
Debug|Any CPU = Debug|Any CPU
34+
Release|Any CPU = Release|Any CPU
35+
EndGlobalSection
36+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
37+
{C550B95D-65D5-407A-9DE4-628EA1473D68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{C550B95D-65D5-407A-9DE4-628EA1473D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{C550B95D-65D5-407A-9DE4-628EA1473D68}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{C550B95D-65D5-407A-9DE4-628EA1473D68}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{1756216A-0EC9-42A0-AB0A-B2C01F07698C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{1756216A-0EC9-42A0-AB0A-B2C01F07698C}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{1756216A-0EC9-42A0-AB0A-B2C01F07698C}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{1756216A-0EC9-42A0-AB0A-B2C01F07698C}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{0CA08585-BC86-4478-B497-D14FB7FF8FE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{0CA08585-BC86-4478-B497-D14FB7FF8FE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{0CA08585-BC86-4478-B497-D14FB7FF8FE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{0CA08585-BC86-4478-B497-D14FB7FF8FE2}.Release|Any CPU.Build.0 = Release|Any CPU
49+
EndGlobalSection
50+
GlobalSection(SolutionProperties) = preSolution
51+
HideSolutionNode = FALSE
52+
EndGlobalSection
53+
GlobalSection(NestedProjects) = preSolution
54+
{C550B95D-65D5-407A-9DE4-628EA1473D68} = {037440DE-440B-4129-9F7A-09B42D00397E}
55+
{1756216A-0EC9-42A0-AB0A-B2C01F07698C} = {CF817664-4CEC-4B6A-9C57-A0D687757D82}
56+
{0CA08585-BC86-4478-B497-D14FB7FF8FE2} = {7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}
57+
EndGlobalSection
58+
GlobalSection(ExtensibilityGlobals) = postSolution
59+
SolutionGuid = {7C0BB51E-642A-476E-A976-DFD988A95C6D}
60+
EndGlobalSection
61+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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;
16+
using Serilog.Configuration;
17+
using Serilog.Core;
18+
using Serilog.Events;
19+
using Serilog.Formatting;
20+
using Serilog.Formatting.Display;
21+
using Serilog.Sinks.Debug;
22+
23+
namespace Serilog
24+
{
25+
/// <summary>
26+
/// Adds the WriteTo.Debug() extension method to <see cref="LoggerConfiguration"/>.
27+
/// </summary>
28+
public static class ConsoleLoggerConfigurationExtensions
29+
{
30+
const string DefaultDebugOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
31+
32+
/// <summary>
33+
/// Writes log events to <see cref="System.Diagnostics.Debug"/>.
34+
/// </summary>
35+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
36+
/// <param name="restrictedToMinimumLevel">The minimum level for
37+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
38+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
39+
/// to be changed at runtime.</param>
40+
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
41+
/// the default is <code>"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"</code>.</param>
42+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
43+
/// <returns>Configuration object allowing method chaining.</returns>
44+
public static LoggerConfiguration Debug(
45+
this LoggerSinkConfiguration sinkConfiguration,
46+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
47+
string outputTemplate = DefaultDebugOutputTemplate,
48+
IFormatProvider formatProvider = null,
49+
LoggingLevelSwitch levelSwitch = null)
50+
{
51+
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
52+
if (outputTemplate == null) throw new ArgumentNullException(nameof(outputTemplate));
53+
54+
var formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
55+
return sinkConfiguration.Debug(formatter, restrictedToMinimumLevel, levelSwitch);
56+
}
57+
58+
/// <summary>
59+
/// Writes log events to <see cref="System.Diagnostics.Debug"/>.
60+
/// </summary>
61+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
62+
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To
63+
/// control plain text formatting, use the overload that accepts an output template.</param>
64+
/// <param name="restrictedToMinimumLevel">The minimum level for
65+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
66+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
67+
/// to be changed at runtime.</param>
68+
/// <returns>Configuration object allowing method chaining.</returns>
69+
public static LoggerConfiguration Debug(
70+
this LoggerSinkConfiguration sinkConfiguration,
71+
ITextFormatter formatter,
72+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
73+
LoggingLevelSwitch levelSwitch = null)
74+
{
75+
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
76+
if (formatter == null) throw new ArgumentNullException(nameof(formatter));
77+
78+
return sinkConfiguration.Sink(new DebugSink(formatter), restrictedToMinimumLevel, levelSwitch);
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)