Skip to content

Commit 9567f03

Browse files
authored
Merge pull request #28 from serilog/dev
8.0.0 Release
2 parents 68cb453 + 7cf2ee8 commit 9567f03

31 files changed

+541
-572
lines changed

Diff for: Build.ps1

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ foreach ($src in ls src/*) {
2323

2424
echo "build: Packaging project in $src"
2525

26-
& dotnet build -c Release --version-suffix=$buildSuffix
26+
& dotnet build -c Release /p:ContinuousIntegrationBuild=True --version-suffix=$buildSuffix
27+
if($LASTEXITCODE -ne 0) { throw "Build failed" }
2728

2829
if($suffix) {
2930
& dotnet pack -c Release --no-build -o ..\..\artifacts --version-suffix=$suffix
3031
} else {
3132
& dotnet pack -c Release --no-build -o ..\..\artifacts
3233
}
33-
if($LASTEXITCODE -ne 0) { exit 1 }
34+
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }
3435

3536
Pop-Location
3637
}
@@ -41,7 +42,7 @@ foreach ($test in ls test/*.Tests) {
4142
echo "build: Testing project in $test"
4243

4344
& dotnet test -c Release
44-
if($LASTEXITCODE -ne 0) { exit 3 }
45+
if($LASTEXITCODE -ne 0) { throw "Testing failed failed" }
4546

4647
Pop-Location
4748
}

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Serilog.Sinks.BrowserConsole [![Build status](https://ci.appveyor.com/api/projects/status/s458q719m2pfwnyk?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-browserconsole) [![NuGet Pre Release](https://img.shields.io/nuget/vpre/Serilog.Sinks.BrowserConsole.svg)](https://nuget.org/packages/Serilog.Sinks.BrowserConsole)
22

3-
A console sink for the Blazor/Wasm environment.
3+
A Serilog sink that takes advantage of the unique features of the browser console in the Blazor/WASM applications.
4+
5+
**Versioning:** This package tracks the versioning and target framework support of its _Microsoft.AspNetCore.Components.WebAssembly_ dependency. Most users should choose the version of _Serilog.Sinks.BrowserConsole_ that matches their application's target framework. I.e. if you're targeting .NET 7.x, choose a 7.x version of _Serilog.Sinks.BrowserConsole_. If you're targeting .NET 8.x, choose an 8.x _Serilog.Sinks.BrowserConsole_ version, and so on.
46

57
### What's it do?
68

@@ -13,7 +15,7 @@ The sink writes log events to the browser console. Unlike the normal Serilog con
1315
Configure the logging pipeline in `Program.Main()`:
1416

1517
```csharp
16-
// dotnet add package Serilog.Sinks.BrowserConsole -v ...
18+
// dotnet add package Serilog.Sinks.BrowserConsole
1719
1820
Log.Logger = new LoggerConfiguration()
1921
.WriteTo.BrowserConsole()

Diff for: appveyor.yml

+19-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
version: '{build}'
22
skip_tags: true
3-
image: Visual Studio 2022
4-
test: off
5-
install:
6-
- ps: $RequiredDotnetVersion = $(Get-Content ./global.json | ConvertFrom-Json).sdk.version
7-
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk"
8-
- ps: mkdir $env:DOTNET_INSTALL_DIR -Force | Out-Null
9-
- ps: Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1"
10-
- ps: '& "$($env:DOTNET_INSTALL_DIR)/dotnet-install.ps1" -Version $RequiredDotnetVersion -InstallDir $env:DOTNET_INSTALL_DIR'
11-
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
3+
image:
4+
- Visual Studio 2022
125
build_script:
13-
- ps: ./Build.ps1
6+
- pwsh: ./Build.ps1
7+
test: off
148
artifacts:
15-
- path: artifacts/Serilog.*.nupkg
9+
- path: artifacts/Serilog.*.nupkg
10+
- path: artifacts/Serilog.*.snupkg
1611
deploy:
17-
- provider: NuGet
18-
api_key:
19-
secure: +2WKSa0MD8rYcyOATIFS3hOQQ6DpbabIqbldh/yFBajpeHwahh+pENharnkJgdn4
20-
skip_symbols: true
21-
on:
22-
branch: /^(main|dev)$/
23-
- provider: GitHub
24-
auth_token:
25-
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
26-
artifact: /Serilog.*\.nupkg/
27-
tag: v$(appveyor_build_version)
28-
on:
29-
branch: main
12+
- provider: NuGet
13+
api_key:
14+
secure: sDnchSg4TZIOK7oIUI6BJwFPNENTOZrGNsroGO1hehLJSvlHpFmpTwiX8+bgPD+Q
15+
on:
16+
branch: /^(main|dev)$/
17+
- provider: GitHub
18+
auth_token:
19+
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
20+
artifact: /Serilog.*(\.|\.s)nupkg/
21+
tag: v$(appveyor_build_version)
22+
on:
23+
branch: main
24+

Diff for: example/ExampleClient/ExampleClient.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
9-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.0" />
10-
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.7" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.7" />
10+
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

Diff for: example/ExampleClient/Program.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
using Serilog.Debugging;
77
using System.Threading.Tasks;
88

9-
namespace ExampleClient
9+
namespace ExampleClient;
10+
11+
public class Program
1012
{
11-
public class Program
13+
public static async Task Main(string[] args)
1214
{
13-
public static async Task Main(string[] args)
14-
{
1515
SelfLog.Enable(m => Console.Error.WriteLine(m));
1616

1717
Log.Logger = new LoggerConfiguration()
@@ -38,5 +38,4 @@ public static async Task Main(string[] args)
3838
throw;
3939
}
4040
}
41-
}
42-
}
41+
}

Diff for: global.json

-6
This file was deleted.

Diff for: serilog-sinks-browserconsole.sln

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{92992D61-AAE
1010
Build.ps1 = Build.ps1
1111
LICENSE = LICENSE
1212
README.md = README.md
13-
global.json = global.json
1413
EndProjectSection
1514
EndProject
1615
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B4B852D3-EAD7-40BC-AE0C-2C7FF8E3D9BE}"

Diff for: serilog-sinks-browserconsole.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=JS/@EntryIndexedValue">JS</s:String></wpf:ResourceDictionary>

Diff for: src/Serilog.Sinks.BrowserConsole/LoggerConfigurationBrowserConsoleExtensions.cs

+33-35
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,48 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System;
1615
using Microsoft.JSInterop;
1716
using Serilog.Configuration;
1817
using Serilog.Core;
1918
using Serilog.Events;
2019
using Serilog.Sinks.BrowserConsole;
2120
using Serilog.Sinks.BrowserConsole.Output;
2221

23-
namespace Serilog
22+
namespace Serilog;
23+
24+
/// <summary>
25+
/// Adds the WriteTo.BrowserConsole() extension method to <see cref="LoggerConfiguration"/>.
26+
/// </summary>
27+
public static class LoggerConfigurationBrowserConsoleExtensions
2428
{
29+
const string SerilogToken =
30+
"%cserilog{_}color:white;background:#8c7574;border-radius:3px;padding:1px 2px;font-weight:600;";
31+
32+
const string DefaultConsoleOutputTemplate = SerilogToken + "{Message}{NewLine}{Exception}";
33+
2534
/// <summary>
26-
/// Adds the WriteTo.BrowserConsole() extension method to <see cref="LoggerConfiguration"/>.
35+
/// Writes log events to the browser console.
2736
/// </summary>
28-
public static class LoggerConfigurationBrowserConsoleExtensions
37+
/// <param name="sinkConfiguration">Logger sink configuration.</param>
38+
/// <param name="restrictedToMinimumLevel">The minimum level for
39+
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</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+
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
44+
/// to be changed at runtime.</param>
45+
/// <param name="jsRuntime">An instance of <see cref="IJSRuntime"/> to interact with the browser.</param>
46+
/// <returns>Configuration object allowing method chaining.</returns>
47+
public static LoggerConfiguration BrowserConsole(
48+
this LoggerSinkConfiguration sinkConfiguration,
49+
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
50+
string outputTemplate = DefaultConsoleOutputTemplate,
51+
IFormatProvider? formatProvider = null,
52+
LoggingLevelSwitch? levelSwitch = null,
53+
IJSRuntime? jsRuntime = null)
2954
{
30-
const string SerilogToken =
31-
"%cserilog{_}color:white;background:#8c7574;border-radius:3px;padding:1px 2px;font-weight:600;";
32-
33-
const string DefaultConsoleOutputTemplate = SerilogToken + "{Message}{NewLine}{Exception}";
34-
35-
/// <summary>
36-
/// Writes log events to the browser console.
37-
/// </summary>
38-
/// <param name="sinkConfiguration">Logger sink configuration.</param>
39-
/// <param name="restrictedToMinimumLevel">The minimum level for
40-
/// events passed through the sink. Ignored when <paramref name="levelSwitch"/> is specified.</param>
41-
/// <param name="outputTemplate">A message template describing the format used to write to the sink.
42-
/// The default is <code>"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"</code>.</param>
43-
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
44-
/// <param name="levelSwitch">A switch allowing the pass-through minimum level
45-
/// to be changed at runtime.</param>
46-
/// <param name="jsRuntime">An instance of <see cref="IJSRuntime"/> to interact with the browser.</param>
47-
/// <returns>Configuration object allowing method chaining.</returns>
48-
public static LoggerConfiguration BrowserConsole(
49-
this LoggerSinkConfiguration sinkConfiguration,
50-
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
51-
string outputTemplate = DefaultConsoleOutputTemplate,
52-
IFormatProvider formatProvider = null,
53-
LoggingLevelSwitch levelSwitch = null,
54-
IJSRuntime jsRuntime = null)
55-
{
56-
if (sinkConfiguration == null) throw new ArgumentNullException(nameof(sinkConfiguration));
57-
var formatter = new OutputTemplateRenderer(outputTemplate, formatProvider);
58-
return sinkConfiguration.Sink(new BrowserConsoleSink(jsRuntime, formatter), restrictedToMinimumLevel, levelSwitch);
59-
}
55+
ArgumentNullException.ThrowIfNull(sinkConfiguration);
56+
var formatter = new OutputTemplateRenderer(outputTemplate, formatProvider);
57+
return sinkConfiguration.Sink(new BrowserConsoleSink(jsRuntime, formatter), restrictedToMinimumLevel, levelSwitch);
6058
}
61-
}
59+
}

Diff for: src/Serilog.Sinks.BrowserConsole/Properties/AssemblyInfo.cs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,40 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
5-
<VersionPrefix>2.0.0</VersionPrefix>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<!-- TFMs supported by this package are aligned with Microsoft.AspNetCore.Components.WebAssembly supported TFMs. -->
6+
<VersionPrefix>8.0.0</VersionPrefix>
67
<RootNamespace>Serilog</RootNamespace>
7-
<Description>Simple .NET logging with fully-structured events</Description>
8+
<Description>Writes Serilog events to the browser console</Description>
89
<Authors>Serilog Contributors</Authors>
910
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1011
<PackageTags>serilog;blazor</PackageTags>
1112
<PackageIcon>icon.png</PackageIcon>
1213
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-browserconsole</PackageProjectUrl>
1314
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
14-
<RepositoryUrl>https://github.com/serilog/serilog-sinks-browserconsole</RepositoryUrl>
15-
<RepositoryType>git</RepositoryType>
16-
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
1715
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
1816
<TreatSpecificWarningsAsErrors />
17+
<PackageReadmeFile>README.md</PackageReadmeFile>
18+
<LangVersion>latest</LangVersion>
19+
<ImplicitUsings>enable</ImplicitUsings>
20+
<PackageReadmeFile>README.md</PackageReadmeFile>
21+
<Nullable>enable</Nullable>
22+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
23+
<IncludeSymbols>true</IncludeSymbols>
1924
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<InternalsVisibleTo Include="Serilog.Sinks.BrowserConsole.Tests" />
28+
</ItemGroup>
2029

2130
<ItemGroup>
22-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.0" />
23-
<PackageReference Include="Serilog" Version="2.10.0" />
31+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.7" />
32+
<PackageReference Include="Serilog" Version="4.0.0" />
2433
</ItemGroup>
2534

2635
<ItemGroup>
2736
<None Include="..\..\assets\icon.png" Pack="true" Visible="false" PackagePath="" />
37+
<None Include="..\..\README.md" Pack="true" Visible="false" PackagePath="" />
2838
</ItemGroup>
2939

3040
</Project>

Diff for: src/Serilog.Sinks.BrowserConsole/Sinks/BrowserConsole/BrowserConsoleSink.cs

+29-28
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,42 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System;
1615
using Microsoft.JSInterop;
1716
using Serilog.Core;
17+
using Serilog.Debugging;
1818
using Serilog.Events;
1919
using Serilog.Sinks.BrowserConsole.Output;
2020

21-
namespace Serilog.Sinks.BrowserConsole
21+
namespace Serilog.Sinks.BrowserConsole;
22+
23+
class BrowserConsoleSink : ILogEventSink
2224
{
23-
class BrowserConsoleSink : ILogEventSink
25+
readonly IJSRuntime _runtime;
26+
readonly OutputTemplateRenderer _formatter;
27+
28+
public BrowserConsoleSink(IJSRuntime? runtime, OutputTemplateRenderer formatter)
2429
{
25-
readonly IJSRuntime _runtime;
26-
readonly OutputTemplateRenderer _formatter;
30+
_runtime = runtime ?? DefaultWebAssemblyJSRuntime.Instance;
31+
_formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
32+
}
2733

28-
public BrowserConsoleSink(IJSRuntime runtime, OutputTemplateRenderer formatter)
29-
{
30-
_runtime = runtime ?? DefaultWebAssemblyJSRuntime.Instance;
31-
_formatter = formatter ?? throw new ArgumentNullException(nameof(formatter));
32-
}
34+
public void Emit(LogEvent logEvent)
35+
{
36+
ArgumentNullException.ThrowIfNull(logEvent);
37+
var outputStream = SelectConsoleMethod(logEvent.Level);
38+
var args = _formatter.Format(logEvent);
39+
_runtime.InvokeAsync<string>(outputStream, args)
40+
.AsTask()
41+
.ContinueWith(t => SelfLog.WriteLine("Failed to emit log event: {0}", t.Exception), TaskContinuationOptions.OnlyOnFaulted);
42+
}
3343

34-
public void Emit(LogEvent logEvent)
44+
static string SelectConsoleMethod(LogEventLevel logLevel) =>
45+
logLevel switch
3546
{
36-
if (logEvent == null) throw new ArgumentNullException(nameof(logEvent));
37-
var outputStream = SelectConsoleMethod(logEvent.Level);
38-
var args = _formatter.Format(logEvent);
39-
var _ = _runtime.InvokeAsync<string>(outputStream, args);
40-
}
41-
42-
static string SelectConsoleMethod(LogEventLevel logLevel) =>
43-
logLevel switch
44-
{
45-
>= LogEventLevel.Error => "console.error",
46-
LogEventLevel.Warning => "console.warn",
47-
LogEventLevel.Information => "console.info",
48-
LogEventLevel.Debug => "console.debug",
49-
_ => "console.log"
50-
};
51-
}
52-
}
47+
>= LogEventLevel.Error => "console.error",
48+
LogEventLevel.Warning => "console.warn",
49+
LogEventLevel.Information => "console.info",
50+
LogEventLevel.Debug => "console.debug",
51+
_ => "console.log"
52+
};
53+
}

0 commit comments

Comments
 (0)