Code Monkey home page Code Monkey logo

serilog-ui's Introduction

serilog-ui

A simple Serilog log viewer for following sinks:

serilog ui

Install the Serilog.UI NuGet package

Install-Package Serilog.UI

Then install one of the providers based upon your sink:

Provider Name Install Package
Serilog.UI.MsSqlServerProvider Install-Package Serilog.UI.MsSqlServerProvider NuGet package
Serilog.UI.MySqlProvider Install-Package Serilog.UI.MySqlProvider NuGet package
Serilog.UI.PostgreSqlProvider Install-Package Serilog.UI.PostgreSqlProvider NuGet package
Serilog.UI.MongoDbProviderr Install-Package Serilog.UI.MongoDbProvider NuGet package
Serilog.UI.ElasticSearchProvider Install-Package Serilog.UI.ElasticSearcProvider NuGet package

Then, add AddSerilogUi() to IServiceCollection in Startup.ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    // Register the serilog UI services
    services.AddSerilogUi(options => options.UseSqlServer("ConnectionString", "LogTableName"));
}

In the Startup.Configure method, enable the middleware for serving logs UI. Place a call to the UseSerilogUi middleware after authentication and authorization middlewares otherwise authentication may not work for you:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    .
    .
    .

    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
        
    // Enable middleware to serve log-ui (HTML, JS, CSS, etc.).
    app.UseSerilogUi();

    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
    });
}

Default url to view log page is http://<your-app>/serilog-ui. If you want to change this url path, just config route prefix:

app.UseSerilogUi(option => option.RoutePrefix = "logs");

Authorization configuration required

By default serilog-ui allows access to log page only for local requests. In order to give appropriate rights for production use, you need to configuring authorization. You can secure log page by allwoing specific users or roles to view logs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSerilogUi(options => options
        .EnableAuthorization(authOptions =>
        {
            authOption.AuthenticationType = AuthenticationType.Jwt; // or AuthenticationType.Cookie
            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. If you set AuthenticationType to Jwt, you can set jwt token and Authorization header will be added to the request and for Cookie just login into you website and no extra step is required.

Limitation

  • Additional columns are not supported and only main columns can be retrieved

serilog-ui's People

Contributors

mo-esmp avatar ricardodemauro avatar hansoncaleb avatar chaadfh avatar dependabot[bot] avatar

Stargazers

SeppPenner avatar

Watchers

 avatar

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.