Skip to content

Commit 4f61421

Browse files
authored
Merge pull request #147 from serilog/dev
5.0.0 Release
2 parents 565c284 + 30b4abb commit 4f61421

18 files changed

+570
-126
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ artifacts:
99
deploy:
1010
- provider: NuGet
1111
api_key:
12-
secure: oemq1E4zMR+LKQyrR83ZLcugPpZtl5OMKjtpMy/mbPEwuFGS+Oe46427D9KoHYD8
12+
secure: dX4ewxGxhiNURkqJPuZQ8GQNjLvb8oZrHBThVotn+9GSMyQzeKXFpHkN04ykOfgc
1313
skip_symbols: true
1414
on:
1515
branch: /^(main|dev)$/

sample/ConsoleDemo/ConsoleDemo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFrameworks>netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48;net5.0</TargetFrameworks>
5+
<TargetFramework>net7.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

sample/SyncWritesDemo/SyncWritesDemo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net7.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 Serilog.Configuration;
16+
using Serilog.Core;
17+
using Serilog.Events;
18+
using Serilog.Formatting;
19+
using Serilog.Sinks.SystemConsole;
20+
using Serilog.Sinks.SystemConsole.Output;
21+
using Serilog.Sinks.SystemConsole.Themes;
22+
using System;
23+
24+
namespace Serilog
25+
{
26+
/// <summary>
27+
/// Adds the AuditTo.Console() extension method to <see cref="LoggerAuditSinkConfiguration"/>.
28+
/// </summary>
29+
public static class ConsoleAuditLoggerConfigurationExtensions
30+
{
31+
/// <summary>
32+
/// Writes log events to <see cref="System.Console"/>.
33+
/// </summary>
34+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
35+
/// <param name="restrictedToMinimumLevel">The minimum level for
36+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
37+
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
38+
/// The default is <code>"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"</code>.</param>
39+
/// <param name="syncRoot">An object that will be used to `lock` (sync) access to the console output. If you specify this, you
40+
/// will have the ability to lock on this object, and guarantee that the console sink will not be about to output anything while
41+
/// the lock is held.</param>
42+
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
43+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
44+
/// to be changed at runtime.</param>
45+
/// <param name="standardErrorFromLevel">Specifies the level at which events will be written to standard error.</param>
46+
/// <param name="theme">The theme to apply to the styled output. If not specified,
47+
/// uses <see cref="SystemConsoleTheme.Literate"/>.</param>
48+
/// <param name="applyThemeToRedirectedOutput">Applies the selected or default theme even when output redirection is detected.</param>
49+
/// <returns>Configuration object allowing method chaining.</returns>
50+
/// <exception cref="ArgumentNullException">When <paramref name="sinkConfiguration"/> is <code>null</code></exception>
51+
/// <exception cref="ArgumentNullException">When <paramref name="outputTemplate"/> is <code>null</code></exception>
52+
public static LoggerConfiguration Console(
53+
this LoggerAuditSinkConfiguration sinkConfiguration,
54+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
55+
string outputTemplate = ConsoleLoggerConfigurationExtensions.DefaultConsoleOutputTemplate,
56+
IFormatProvider? formatProvider = null,
57+
LoggingLevelSwitch? levelSwitch = null,
58+
LogEventLevel? standardErrorFromLevel = null,
59+
ConsoleTheme? theme = null,
60+
bool applyThemeToRedirectedOutput = false,
61+
object? syncRoot = null)
62+
{
63+
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
64+
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));
65+
66+
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ?
67+
ConsoleTheme.None :
68+
theme ?? SystemConsoleThemes.Literate;
69+
70+
syncRoot ??= ConsoleLoggerConfigurationExtensions.DefaultSyncRoot;
71+
72+
var formatter = new OutputTemplateRenderer(appliedTheme, outputTemplate, formatProvider);
73+
return sinkConfiguration.Sink(new ConsoleSink(appliedTheme, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch);
74+
}
75+
76+
/// <summary>
77+
/// Writes log events to <see cref="System.Console"/>.
78+
/// </summary>
79+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
80+
/// <param name="formatter">Controls the rendering of log events into text, for example to log JSON. To
81+
/// control plain text formatting, use the overload that accepts an output template.</param>
82+
/// <param name="syncRoot">An object that will be used to `lock` (sync) access to the console output. If you specify this, you
83+
/// will have the ability to lock on this object, and guarantee that the console sink will not be about to output anything while
84+
/// the lock is held.</param>
85+
/// <param name="restrictedToMinimumLevel">The minimum level for
86+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
87+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
88+
/// to be changed at runtime.</param>
89+
/// <param name="standardErrorFromLevel">Specifies the level at which events will be written to standard error.</param>
90+
/// <returns>Configuration object allowing method chaining.</returns>
91+
/// <exception cref="ArgumentNullException">When <paramref name="sinkConfiguration"/> is <code>null</code></exception>
92+
/// <exception cref="ArgumentNullException">When <paramref name="formatter"/> is <code>null</code></exception>
93+
public static LoggerConfiguration Console(
94+
this LoggerAuditSinkConfiguration sinkConfiguration,
95+
ITextFormatter formatter,
96+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
97+
LoggingLevelSwitch? levelSwitch = null,
98+
LogEventLevel? standardErrorFromLevel = null,
99+
object? syncRoot = null)
100+
{
101+
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
102+
if (formatter is null) throw new ArgumentNullException(nameof(formatter));
103+
104+
syncRoot ??= ConsoleLoggerConfigurationExtensions.DefaultSyncRoot;
105+
106+
return sinkConfiguration.Sink(new ConsoleSink(ConsoleTheme.None, formatter, standardErrorFromLevel, syncRoot), restrictedToMinimumLevel, levelSwitch);
107+
}
108+
}
109+
}

src/Serilog.Sinks.Console/ConsoleLoggerConfigurationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace Serilog
2828
/// </summary>
2929
public static class ConsoleLoggerConfigurationExtensions
3030
{
31-
static readonly object DefaultSyncRoot = new object();
32-
const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
31+
internal static readonly object DefaultSyncRoot = new object();
32+
internal const string DefaultConsoleOutputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
3333

3434
/// <summary>
3535
/// Writes log events to <see cref="System.Console"/>.
Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,50 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
4+
<VersionPrefix>5.0.0</VersionPrefix>
5+
<Authors>Serilog Contributors</Authors>
6+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net462;net471</TargetFrameworks>
7+
<TargetFrameworks>$(TargetFrameworks);netstandard2.1;netstandard2.0;net5.0;net6.0;net7.0</TargetFrameworks>
8+
<Nullable>enable</Nullable>
9+
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
10+
<SignAssembly>true</SignAssembly>
11+
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
12+
<PackageTags>serilog;console;terminal</PackageTags>
13+
<PackageIcon>icon.png</PackageIcon>
14+
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-console</PackageProjectUrl>
15+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
16+
<RepositoryUrl>https://github.com/serilog/serilog-sinks-console</RepositoryUrl>
17+
<RepositoryType>git</RepositoryType>
18+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
19+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
20+
<RootNamespace>Serilog</RootNamespace>
21+
<LangVersion>latest</LangVersion>
22+
<PackageReadmeFile>README.md</PackageReadmeFile>
23+
</PropertyGroup>
224

3-
<PropertyGroup>
4-
<Description>A Serilog sink that writes log events to the console/terminal.</Description>
5-
<VersionPrefix>4.1.0</VersionPrefix>
6-
<Authors>Serilog Contributors</Authors>
7-
<TargetFrameworks>net45;netstandard1.3;netstandard2.0;net5.0</TargetFrameworks>
8-
<LangVersion>8.0</LangVersion>
9-
<Nullable>enable</Nullable>
10-
<AssemblyOriginatorKeyFile>../../assets/Serilog.snk</AssemblyOriginatorKeyFile>
11-
<SignAssembly>true</SignAssembly>
12-
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
13-
<PackageTags>serilog;console;terminal</PackageTags>
14-
<PackageIcon>icon.png</PackageIcon>
15-
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-console</PackageProjectUrl>
16-
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
17-
<RepositoryUrl>https://github.com/serilog/serilog-sinks-console</RepositoryUrl>
18-
<RepositoryType>git</RepositoryType>
19-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
20-
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
21-
<TreatSpecificWarningsAsErrors />
22-
<RootNamespace>Serilog</RootNamespace>
23-
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(TargetFramework)' != 'net462' ">
26+
<DefineConstants>$(DefineConstants);RUNTIME_INFORMATION</DefineConstants>
27+
</PropertyGroup>
2428

25-
<PropertyGroup Condition=" '$(TargetFramework)' != 'net45' ">
26-
<DefineConstants>$(DefineConstants);RUNTIME_INFORMATION</DefineConstants>
27-
</PropertyGroup>
28-
29-
<ItemGroup>
30-
<PackageReference Include="Serilog" Version="2.10.0" />
31-
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
32-
</ItemGroup>
29+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
30+
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants>
31+
</PropertyGroup>
32+
33+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
34+
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants>
35+
</PropertyGroup>
36+
37+
<PropertyGroup Condition=" '$(TargetFramework)' == 'net7.0' ">
38+
<DefineConstants>$(DefineConstants);FEATURE_SPAN</DefineConstants>
39+
</PropertyGroup>
40+
41+
<ItemGroup>
42+
<PackageReference Include="Serilog" Version="3.1.0-*" />
43+
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" />
44+
</ItemGroup>
3345

34-
<ItemGroup>
35-
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" />
36-
</ItemGroup>
46+
<ItemGroup>
47+
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" />
48+
<None Include="..\..\README.md" Pack="true" Visible="false" PackagePath="" />
49+
</ItemGroup>
3750
</Project>

0 commit comments

Comments
 (0)