Skip to content

Simple Serilog log viewer UI for several sinks.

License

Notifications You must be signed in to change notification settings

TimSirmovics/serilog-ui

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serilog-ui

A simple log viewer to see logs saved by Serilog.Sinks.MSSqlServer or Serilog.Sinks.Postgresql (other sinks will be added in the future).

serilog ui

Install the Serilog.UI NuGet package and Serilog.Ui.MsSqlServerProvider NuGet package:

Install-Package Serilog.UI

Then based on your databasbe install a provider, Serilog.Ui.MsSqlServerProvider NuGet package:

Install-Package Serilog.UI.MsSqlServerProvider

or Serilog.Ui.PostgreSqlProvider NuGet package:

Install-Package Serilog.Ui.PostgreSqlProvider

Then, add UseSerilogUi() to IServiceCollection in ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    var mvcBuilder = services.AddControllersWithViews();
    services.AddSerilogUi(mvcBuilder, options => options.UseSqlServer("ConnectionString", "LogTableName"));
    // or
    // services.AddSerilogUi(mvcBuilder, options => options.UseNpgSql("ConnectionString", "LogTableName"));
    .
    .
    .

You can also secure log viewer by allwoing specific users or roles to view logs:

public void ConfigureServices(IServiceCollection services)
{
    var mvcBuilder = services.AddControllersWithViews();
    services.AddSerilogUi(mvcBuilder, options => options
        .EnableAuthorization(authOptions =>
        {
            authOptions.Usernames = new[] { "User1", "User2" };
            authOptions.Roles = new[] { "AdminRole" };
        })
        .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), "LogTableName"));
    .
    .
    .

Only User1 and User2 or users with AdminRole role can view logs.

Limitation

  • Log url /logs is fix and cannot be changed
  • Log viewer only works with MVC so you have to register views services.AddControllersWithViews(); and also add default route endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
  • Additional columns are not supported and only main columns can be retrieved

About

Simple Serilog log viewer UI for several sinks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 53.7%
  • HTML 23.6%
  • CSS 16.7%
  • JavaScript 6.0%