Skip to content

Commit 6bce34b

Browse files
authored
Merge pull request #16 from serilog/dev
1.0.0 Release
2 parents 00b0c70 + 1bd6af4 commit 6bce34b

Some content is hidden

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

54 files changed

+2376
-2
lines changed

Diff for: Build.ps1

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 "main" -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+
28+
if($suffix) {
29+
& dotnet pack -c Release --no-build -o ..\..\artifacts --version-suffix=$suffix
30+
} else {
31+
& dotnet pack -c Release --no-build -o ..\..\artifacts
32+
}
33+
if($LASTEXITCODE -ne 0) { exit 1 }
34+
35+
Pop-Location
36+
}
37+
38+
foreach ($test in ls test/*.Tests) {
39+
Push-Location $test
40+
41+
echo "build: Testing project in $test"
42+
43+
& dotnet test -c Release
44+
if($LASTEXITCODE -ne 0) { exit 3 }
45+
46+
Pop-Location
47+
}
48+
49+
Pop-Location

Diff for: README.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1-
# serilog-sinks-browserconsole
2-
A console sink for the Blazor/WASM environment
1+
# 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)
2+
3+
A console sink for the Blazor/Wasm environment.
4+
5+
### What's it do?
6+
7+
The sink writes log events to the browser console. Unlike the normal Serilog console sink, which writes out formatted text, this sink takes advantage of the unique capabilities of the browser console to print interactive, fully-structured data.
8+
9+
![Serilog.Sinks.BrowserConsole](https://raw.githubusercontent.com/serilog/serilog-sinks-browserconsole/dev/assets/Screenshot.png)
10+
11+
### Getting started
12+
13+
Configure the logging pipeline in `Program.Main()`:
14+
15+
```csharp
16+
// dotnet add package Serilog.Sinks.BrowserConsole -v ...
17+
18+
Log.Logger = new LoggerConfiguration()
19+
.WriteTo.BrowserConsole()
20+
.CreateLogger();
21+
22+
Log.Information("Hello, browser!");
23+
```
24+
25+
A more detailed example is available [in this repository](https://github.com/serilog/serilog-sinks-browserconsole/tree/dev/example/ExampleClient).

Diff for: 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 2019
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: rbdBqxBpLt4MkB+mrDOYNDOd8aVZ1zMkysaVNAXNKnC41FYifzX3l9LM8DCrUWU5
14+
skip_symbols: true
15+
on:
16+
branch: /^(main|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: main

Diff for: assets/Screenshot.png

121 KB
Loading

Diff for: assets/icon.png

19.9 KB
Loading

Diff for: example/ExampleClient/App.razor

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
10+
</Router>

Diff for: example/ExampleClient/ExampleClient.csproj

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-rc.1.*" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-rc.1.*" />
10+
<PackageReference Include="System.Net.Http.Json" Version="5.0.0-rc.1.*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\Serilog.Sinks.BrowserConsole\Serilog.Sinks.BrowserConsole.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

Diff for: example/ExampleClient/Pages/Counter.razor

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@using Serilog
2+
@page "/counter"
3+
4+
<h1>Counter</h1>
5+
6+
<p>Current count: @currentCount</p>
7+
8+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
9+
10+
@code {
11+
int currentCount = 0;
12+
13+
void IncrementCount()
14+
{
15+
currentCount++;
16+
17+
if (currentCount < 5)
18+
Log.ForContext<Counter>().Information("Incremented count to {CurrentCount}", currentCount);
19+
else
20+
try
21+
{
22+
throw new NotSupportedException("Too many clicks!");
23+
}
24+
catch (Exception ex)
25+
{
26+
Log.Error(ex, "Failed at {CurrentCount}", currentCount);
27+
}
28+
}
29+
}

Diff for: example/ExampleClient/Pages/FetchData.razor

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@page "/fetchdata"
2+
@inject HttpClient _http
3+
4+
<h1>Weather forecast</h1>
5+
6+
<p>This component demonstrates fetching data from the server.</p>
7+
8+
@if (forecasts == null)
9+
{
10+
<p><em>Loading...</em></p>
11+
}
12+
else
13+
{
14+
<table class="table">
15+
<thead>
16+
<tr>
17+
<th>Date</th>
18+
<th>Temp. (C)</th>
19+
<th>Temp. (F)</th>
20+
<th>Summary</th>
21+
</tr>
22+
</thead>
23+
<tbody>
24+
@foreach (var forecast in forecasts)
25+
{
26+
<tr>
27+
<td>@forecast.Date.ToShortDateString()</td>
28+
<td>@forecast.TemperatureC</td>
29+
<td>@forecast.TemperatureF</td>
30+
<td>@forecast.Summary</td>
31+
</tr>
32+
}
33+
</tbody>
34+
</table>
35+
}
36+
37+
@code {
38+
WeatherForecast[] forecasts;
39+
40+
protected override async Task OnInitializedAsync()
41+
{
42+
forecasts = await _http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
43+
}
44+
45+
public class WeatherForecast
46+
{
47+
public DateTime Date { get; set; }
48+
49+
public int TemperatureC { get; set; }
50+
51+
public string Summary { get; set; }
52+
53+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
54+
}
55+
}

Diff for: example/ExampleClient/Pages/Index.razor

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@page "/"
2+
3+
<h1>Hello, world!</h1>
4+
5+
Welcome to your new app.
6+
7+
<SurveyPrompt Title="How is Blazor working for you?" />

Diff for: example/ExampleClient/Program.cs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Net.Http;
3+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Serilog;
6+
using Serilog.Debugging;
7+
using System.Threading.Tasks;
8+
9+
namespace ExampleClient
10+
{
11+
public class Program
12+
{
13+
public static async Task Main(string[] args)
14+
{
15+
SelfLog.Enable(m => Console.Error.WriteLine(m));
16+
17+
Log.Logger = new LoggerConfiguration()
18+
.MinimumLevel.Debug()
19+
.WriteTo.BrowserConsole()
20+
.CreateLogger();
21+
22+
Log.Debug("Hello, browser!");
23+
Log.Warning("Received strange response {@Response} from server", new { Username = "example", Cats = 7 });
24+
25+
try
26+
{
27+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
28+
29+
builder.RootComponents.Add<App>("app");
30+
31+
builder.Services.AddScoped(_ => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
32+
33+
await builder.Build().RunAsync();
34+
}
35+
catch (Exception ex)
36+
{
37+
Log.Fatal(ex, "An exception occurred while creating the WASM host");
38+
throw;
39+
}
40+
}
41+
}
42+
}

Diff for: example/ExampleClient/Shared/MainLayout.razor

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
4+
<NavMenu />
5+
</div>
6+
7+
<div class="main">
8+
<div class="top-row px-4">
9+
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
10+
</div>
11+
12+
<div class="content px-4">
13+
@Body
14+
</div>
15+
</div>

Diff for: example/ExampleClient/Shared/NavMenu.razor

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="top-row pl-4 navbar navbar-dark">
2+
<a class="navbar-brand" href="">ExampleClient-New</a>
3+
<button class="navbar-toggler" @onclick="ToggleNavMenu">
4+
<span class="navbar-toggler-icon"></span>
5+
</button>
6+
</div>
7+
8+
<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">
9+
<ul class="nav flex-column">
10+
<li class="nav-item px-3">
11+
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
12+
<span class="oi oi-home" aria-hidden="true"></span> Home
13+
</NavLink>
14+
</li>
15+
<li class="nav-item px-3">
16+
<NavLink class="nav-link" href="counter">
17+
<span class="oi oi-plus" aria-hidden="true"></span> Counter
18+
</NavLink>
19+
</li>
20+
<li class="nav-item px-3">
21+
<NavLink class="nav-link" href="fetchdata">
22+
<span class="oi oi-list-rich" aria-hidden="true"></span> Fetch data
23+
</NavLink>
24+
</li>
25+
</ul>
26+
</div>
27+
28+
@code {
29+
bool collapseNavMenu = true;
30+
31+
string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
32+
33+
void ToggleNavMenu()
34+
{
35+
collapseNavMenu = !collapseNavMenu;
36+
}
37+
}

Diff for: example/ExampleClient/Shared/SurveyPrompt.razor

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="alert alert-secondary mt-4" role="alert">
2+
<span class="oi oi-pencil mr-2" aria-hidden="true"></span>
3+
<strong>@Title</strong>
4+
5+
<span class="text-nowrap">
6+
Please take our
7+
<a target="_blank" class="font-weight-bold" href="https://go.microsoft.com/fwlink/?linkid=2100553">brief survey</a>
8+
</span>
9+
and tell us what you think.
10+
</div>
11+
12+
@code {
13+
// Demonstrates how a parent component can supply parameters
14+
[Parameter] public string Title { get; set; }
15+
}

Diff for: example/ExampleClient/_Imports.razor

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@using System.Net.Http
2+
@using System.Net.Http.Json
3+
@using Microsoft.AspNetCore.Components.Forms
4+
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
6+
@using Microsoft.AspNetCore.Components.WebAssembly.Http
7+
@using Microsoft.JSInterop
8+
@using ExampleClient
9+
@using ExampleClient.Shared

Diff for: example/ExampleClient/wwwroot/css/bootstrap/bootstrap.min.css

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: example/ExampleClient/wwwroot/css/bootstrap/bootstrap.min.css.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)