generated from NetCoreTemplates/blazor-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using ServiceStack.Jobs; | ||
using ServiceStack.Web; | ||
|
||
[assembly: HostingStartup(typeof(MyApp.ConfigureRequestLogs))] | ||
|
||
namespace MyApp; | ||
|
||
public class ConfigureRequestLogs : IHostingStartup | ||
{ | ||
public void Configure(IWebHostBuilder builder) => builder | ||
.ConfigureServices((context, services) => { | ||
services.AddPlugin(new RequestLogsFeature { | ||
RequestLogger = new SqliteRequestLogger(), | ||
EnableResponseTracking = true, | ||
EnableRequestBodyTracking = true, | ||
EnableErrorTracking = true | ||
}); | ||
services.AddHostedService<RequestLogsHostedService>(); | ||
}); | ||
} | ||
|
||
public class RequestLogsHostedService(ILogger<RequestLogsHostedService> log, IRequestLogger requestLogger) : BackgroundService | ||
{ | ||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
var dbRequestLogger = (SqliteRequestLogger)requestLogger; | ||
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(3)); | ||
while (!stoppingToken.IsCancellationRequested && await timer.WaitForNextTickAsync(stoppingToken)) | ||
{ | ||
dbRequestLogger.Tick(log); | ||
} | ||
} | ||
} |