Skip to content

Commit ae62bb9

Browse files
authored
Update Readme file.
1 parent e93e90d commit ae62bb9

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,59 @@ of _Serilog.UI.MongoDbProvider_ [Nuget package](https://www.nuget.org/packages/S
2626
Install-Package Serilog.UI.MongoDbProvider
2727
```
2828

29-
Then, add `UseSerilogUi()` to `IServiceCollection` in `ConfigureServices` method:
29+
Then, add `AddSerilogUi()` to `IServiceCollection` in `Startup.ConfigureServices` method:
3030

3131
```csharp
3232
public void ConfigureServices(IServiceCollection services)
3333
{
34-
var mvcBuilder = services.AddControllersWithViews();
35-
services.AddSerilogUi(mvcBuilder, options => options.UseSqlServer("ConnectionString", "LogTableName"));
34+
// Register the serilog UI services
35+
services.AddSerilogUi(options => options.UseSqlServer("ConnectionString", "LogTableName"));
3636
// or
37-
// services.AddSerilogUi(mvcBuilder, options => options.UseNpgSql("ConnectionString", "LogTableName"));
37+
// services.AddSerilogUi(options => options.UseNpgSql("ConnectionString", "LogTableName"));
3838
// or
39-
// services.AddSerilogUi(mvcBuilder, options => options.UseMongoDb("ConnectionString", "DatabaseName", "CollectionName"))
39+
// services.AddSerilogUi(options => options.UseMongoDb("ConnectionString", "DatabaseName", "CollectionName"))
40+
}
41+
```
42+
43+
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:
44+
45+
```csharp
46+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
47+
{
4048
.
4149
.
4250
.
51+
52+
app.UseRouting();
53+
app.UseAuthentication();
54+
app.UseAuthorization();
55+
56+
// Enable middleware to serve log-ui (HTML, JS, CSS, etc.).
57+
app.UseSerilogUi();
58+
59+
app.UseEndpoints(endpoints =>
60+
{
61+
endpoints.MapControllerRoute(
62+
name: "default",
63+
pattern: "{controller=Home}/{action=Index}/{id?}");
64+
});
65+
}
66+
```
67+
68+
Default url to view logs is `http://<your-app>/serilog-ui`. If you want to change this url path, just config route prefix:
69+
```csharp
70+
app.UseSerilogUi(option => option.RoutePrefix = "logs");
4371
```
72+
**Authorization configuration required**
4473

45-
You can also secure log viewer by allwoing specific users or roles to view logs:
74+
By default serilog-ui allows access to log page only for local requests. In order to give appropriate rights for production use, configuring authorization.You can secure log viewer by allwoing specific users or roles to view logs:
4675
```csharp
4776
public void ConfigureServices(IServiceCollection services)
4877
{
49-
var mvcBuilder = services.AddControllersWithViews();
50-
services.AddSerilogUi(mvcBuilder, options => options
78+
services.AddSerilogUi(options => options
5179
.EnableAuthorization(authOptions =>
5280
{
81+
authOption.AuthenticationType = AuthenticationType.Jwt; // or AuthenticationType.Cookie
5382
authOptions.Usernames = new[] { "User1", "User2" };
5483
authOptions.Roles = new[] { "AdminRole" };
5584
})
@@ -58,9 +87,7 @@ public void ConfigureServices(IServiceCollection services)
5887
.
5988
.
6089
```
61-
Only `User1` and `User2` or users with `AdminRole` role can view logs.
90+
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.
6291

6392
## Limitation
64-
* Log url `/logs` is fix and cannot be changed
65-
* 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?}");`
6693
* Additional columns are not supported and only main columns can be retrieved

0 commit comments

Comments
 (0)