|
1 | 1 | # serilog-ui
|
2 |
| -Simple web UI for several Serilog sinks. |
| 2 | +A simple log viewer to see logs saved by [Serilog.Sinks.MSSqlServer](https://github.com/serilog/serilog-sinks-mssqlserver) (other sinks will be added in the future). |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +Install the _Serilog.UI_ [NuGet package](https://www.nuget.org/packages/Serilog.UI) and _Serilog.Ui.MsSqlServerProvider_ [NuGet package](https://www.nuget.org/packages/Serilog.Ui.MsSqlServerProvider) |
| 7 | + |
| 8 | +```powershell |
| 9 | +Install-Package Serilog.UI |
| 10 | +Install-Package Serilog.UI.MsSqlServerProvider |
| 11 | +``` |
| 12 | +or |
| 13 | +```shell |
| 14 | +dotnet add package Serilog.UI |
| 15 | +dotnet add package Serilog.UI.MsSqlServerProvider |
| 16 | +``` |
| 17 | + |
| 18 | +Then, add `UseSerilogUi()` to `IServiceCollection` in `ConfigureServices` method: |
| 19 | + |
| 20 | +```csharp |
| 21 | +public void ConfigureServices(IServiceCollection services) |
| 22 | +{ |
| 23 | + var mvcBuilder = services.AddControllersWithViews(); |
| 24 | + services.AddSerilogUi(mvcBuilder, options => options.UseSqlServer("ConnectionString", "LogTableName")); |
| 25 | + . |
| 26 | + . |
| 27 | + . |
| 28 | +``` |
| 29 | + |
| 30 | +You can also secure log viewer by allwoing specific users or roles to view logs: |
| 31 | +```csharp |
| 32 | +public void ConfigureServices(IServiceCollection services) |
| 33 | +{ |
| 34 | + var mvcBuilder = services.AddControllersWithViews(); |
| 35 | + services.AddSerilogUi(mvcBuilder, options => options |
| 36 | + .EnableAuthorization(authOptions => |
| 37 | + { |
| 38 | + authOptions.Usernames = new[] { "User1", "User2" }; |
| 39 | + authOptions.Roles = new[] { "AdminRole" }; |
| 40 | + }) |
| 41 | + .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), "LogTableName")); |
| 42 | + . |
| 43 | + . |
| 44 | + . |
| 45 | +``` |
| 46 | +Only `User1` and `User2` or users with `AdminRole` role can view logs. |
| 47 | + |
| 48 | +## Limitation |
| 49 | +* Log url `/logs` is fix and cannot be changed |
| 50 | +* 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?}");` |
| 51 | +* Additional columns are not supported and only main columns can be retrieved |
0 commit comments