Giter VIP home page Giter VIP logo

serilog-sinks-signalr's Introduction

serilog-sinks-signalr

Build status

A Serilog sink that writes events to a SignalR Hub

Configuration from hub application

From within the SignalR server application with a hub named MyHub:

var hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.SignalR(hubContext,
  Serilog.Events.LogEventLevel.Information,
  groupNames: new[] { "CustomGroup"}, // default is null
  userIds: new[] { "JaneD1234" }, // default is null
  excludedConnectionIds: new[] { "12345", "678910" }) // default is null
.CreateLogger();

Configuration from other clients

From any client application with a hub hosted at http://localhost:8080 and a hub implemented named MyHub:

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.SignalRClient("http://localhost:8080",
  Serilog.Events.LogEventLevel.Information,
  hub: "MyHub" // default is LogHub
  groupNames: new[] { "CustomGroup"}, // default is null
  userIds: new[] { "JaneD1234" }) // default is null
.CreateLogger();

SignalR Server

Create a hub class with any name that ends in Hub or use the default name LogHub. Then create a method named receiveLogEvent, which is capable of accepting all data from the sink.

public class MyHub : Hub
{
  public void receiveLogEvent(string[] groups, string[] userIds, Serilog.Sinks.SignalR.Data.LogEvent logEvent)
  {
    // send to all clients
    Clients.All.sendLogEvent(logEvent);
    // just the specified groups
	Clients.Groups(groups).sendLogEvent(logEvent);
    // just the specified users
    Clients.Users(users).sendLogEvent(logEvent);
  }
}

Receiving the log event

Set up a SignalR client and subscribe to the sendLogEvent method.

var connection = new HubConnection("http://localhost:8080");
var hubProxy = connection.CreateHubProxy("MyHub");

hubProxy.On<Serilog.Sinks.SignalR.Data.LogEvent>("sendLogEvent", (logEvent) =>
{
  Console.WriteLine(logEvent.RenderedMessage);
});

serilog-sinks-signalr's People

Contributors

jafin avatar nblumhardt avatar sirkirby avatar

Watchers

 avatar

serilog-sinks-signalr's Issues

Incompatible with Serilog.Sinks.PeriodicBatching v3 [Bug]

Due to changes in interface and sealing of class, not compatible with PeriodicBatching v3

`
Could not load type 'Serilog.Sinks.SignalR.SignalRSink' from assembly 'Serilog.Sinks.SignalR, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10' because the parent type is sealed.

[TypeLoadException: Could not load type 'Serilog.Sinks.SignalR.SignalRSink' from assembly 'Serilog.Sinks.SignalR, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10' because the parent type is sealed.]
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.