Serilog.Sinks.AspNetCore.SignalR
0.2.2
dotnet add package Serilog.Sinks.AspNetCore.SignalR --version 0.2.2
NuGet\Install-Package Serilog.Sinks.AspNetCore.SignalR -Version 0.2.2
<PackageReference Include="Serilog.Sinks.AspNetCore.SignalR" Version="0.2.2" />
paket add Serilog.Sinks.AspNetCore.SignalR --version 0.2.2
#r "nuget: Serilog.Sinks.AspNetCore.SignalR, 0.2.2"
// Install Serilog.Sinks.AspNetCore.SignalR as a Cake Addin
#addin nuget:?package=Serilog.Sinks.AspNetCore.SignalR&version=0.2.2
// Install Serilog.Sinks.AspNetCore.SignalR as a Cake Tool
#tool nuget:?package=Serilog.Sinks.AspNetCore.SignalR&version=0.2.2
Serilog.Sinks.AspNetCore.SignalR
A Serilog sink that writes events as string or object to the given SignalR Hub.
I was Inspired by serilog-sinks-signalr-core and serilog-sinks-signalr, I decided to write my own because non of both worked for me. I always got a Stackoverflow in an Asp.net core 3 application.
Usage and configuration
The hub you want to use with the Sink must inherit from Hub<IHub> or an interface which inherits from it. To have the services in the "UseSerilog(....)" method you need to install the package "Serilog.Extensions.Hosting"
An example as follows:
public class MyOwnExampleHub : Hub<IExampleHub> { // or IHub
}
public interface IExampleHub : IHub {
}
An example setup is as follows:
.Net core
var hub = ServiceProvider.GetService<IHubContext<MyOwnExampleHub, IExampleHub>>(); // or IHub
Log.Logger = new LoggerConfiguration()
.WriteTo.SignalRSink(
hub,
formatProvider: new CustomFormatProvider(),
groups: new [] { "group1", },
userIds: new [] { "user2", },
excludedConnectionIds: new [] { "1", }
)
.CreateLogger();
[...]
Asp.Net core (3)
// In Programm.cs -> CreateHostBuilder method
private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog((hostingContext, service, loggerConfig) =>
{
loggerConfig
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext()
.Enrich.WithProcessId()
.WriteTo.SignalRSink<MyOwnExampleHub, IExampleHub>(
LogEventLevel.Information,
service,
new MyCustomProvider(), // can be null
new string[] {}, // can be null
new string[] {}, // can be null
new string[] {}, // can be null
false); // false is the default value
});
// In Startup.cs -> Configure method
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
endpoints.MapHub<EventHub>("/api/hub");
endpoints.MapHub<LogHub>("/api/hub/logs");
});
Receive the log events
In the client code, subscribe to the SendLogAsString
or SendLogAsObject
method.
C#
var connection = new HubConnectionBuilder()
.WithUrl("<yourURL>")
.Build()
connection.On<string>("SendLogAsString", (string message) => {
Console.WriteLine(message);
});
Javascript / Typescript
this.connection = new HubConnectionBuilder()
.withUrl('<yourURL>')
.configureLogging(LogLevel.Information)
.build();
this.connection
.start()
.then(() => {
this.connection.on('SendLogAsObject', (data: any) => {
console.log(data);
});
})
.catch((err: any) => console.error(err));
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.AspNetCore.SignalR (>= 1.1.0)
- Serilog (>= 2.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Serilog.Sinks.AspNetCore.SignalR:
Repository | Stars |
---|---|
Kareadita/Kavita
Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
|
|
GZTimeWalker/GZCTF
The GZ::CTF project, an open source CTF platform.
|
Version | Downloads | Last updated |
---|