InterlockLedger.WatchDog
3.0.2
dotnet add package InterlockLedger.WatchDog --version 3.0.2
NuGet\Install-Package InterlockLedger.WatchDog -Version 3.0.2
<PackageReference Include="InterlockLedger.WatchDog" Version="3.0.2" />
paket add InterlockLedger.WatchDog --version 3.0.2
#r "nuget: InterlockLedger.WatchDog, 3.0.2"
// Install InterlockLedger.WatchDog as a Cake Addin #addin nuget:?package=InterlockLedger.WatchDog&version=3.0.2 // Install InterlockLedger.WatchDog as a Cake Tool #tool nuget:?package=InterlockLedger.WatchDog&version=3.0.2
InterlockLedger.WatchDog
Introduction
InterlockLedger.WatchDog is a Realtime Message, Event, HTTP (Request & Response) and Exception logger and viewer for ASP.Net 6 Web Apps and APIs. It allows developers log and view messages, events, http requests made to their web application and also exception caught during runtime in their web applications, all in Realtime.
It leverages SignalR
for real-time monitoring and LiteDb
a Serverless MongoDB-like database with no configuration.
General Features
- RealTime HTTP Request and Response Logger
- RealTime Exception Logger
- In-code message and event logging
- User Friendly Logger Views
- Search Option for HTTP and Exception Logs
- Filtering Option for HTTP Logs using HTTP Methods and StatusCode
- Logger View Authentication
- Auto Clear Logs Option
- In-code logger for messages and events
What's New
- Now a privacy filtering class to vet/adjust information to be logged can be injected
- Specify folder to store log database
- Separate extension method to map endpoints for better integration with complex ASP.NET apps
- Diagnostic logging when configuring middleware
Support
- .NET 6.0 and newer
Installation
Install via .NET CLI
dotnet add package InterlockLedger.WatchDog --version 3.0.0
Install via Package Manager
Install-Package InterlockLedger.WatchDog --version 3.0.0
Usage
To enable InterlockLedger.WatchDog to listen for requests, use the WatchDog middleware provided by WatchDog.
Add InterlockLedger.WatchDog Namespace to your startup code file
using InterlockLedger.WatchDog;
Register WatchDog service in the services configuration part of the initialization
services.AddWatchDogServices();
Optional
Change the folder where to create the database for the logs
services.AddWatchDogServices(opt =>
{
opt.DatabaseFolder = "c:\\temp\\watchdog";
// default uses SpecialFolder.LocalApplicationData and executing assembly name
});
Optional
Setup AutoClear Logs
This clears the logs after a specific duration.
services.AddWatchDogServices(opt =>
{
opt.UseAutoClear = true;
});
NOTE When
UseAutoClear = true
Default Schedule Time is set to Weekly, override it like below:
services.AddWatchDogServices(opt =>
{
opt.UseAutoClear = true;
opt.ClearTimeSchedule = WatchDogAutoClearScheduleEnum.Monthly;
});
Add WatchDog middleware in the HTTP request pipeline, with required credentials to enforce
This authentication information (Username and Password) will be used to access the log viewer, unless you specify a role to check first
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
});
NOTE
Important
If your projects startup or program class contains app.UseMvc() or app.UseRouting() then app.UseWatchDog() should come after
Optional
Specify a role that the authenticated user must have to avoid asking the credentials
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
opt.RequiredRole = "LogViewer";
});
Optional
Add list of routes you want to ignore when logging requests
List of routes, paths or specific strings to be ignored should be a comma separated string like below.
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
opt.Blacklist = "Test/testPost,weatherforecast";
});
Optional
Activate WatchDog Exception Logger
This is used to log in-app exceptions that occur during the processing of a particular HTTP request.
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
opt.LogExceptions = true;
});
Optional
Inject privacy filtering of logged information
This is used to inject a class that will look at log details models and tweak them before being stored, to remove sensitive information
builder.Services.AddWatchDogServicesUsing<MyCustomModelsFilter>(opt =>
{
opt.UseAutoClear = true;
opt.ClearTimeSchedule = WatchDogAutoClearScheduleEnum.Monthly;
});```
The class must implement IModelsFilter to do the needed filtering
```c#
class MyCustomModelsFilter : IModelsFilter
{
public ExceptionLogModel FilterExceptionLog(ExceptionLogModel exceptionLogModel, RequestModel requestModel) => exceptionLogModel;
public RequestModel FilterRequest(RequestModel requestModel) {
if (requestModel.Path.Safe().StartsWith("/Private/", StringComparison.OrdinalIgnoreCase))
requestModel.QueryString = "<<sensitive>>";
return requestModel;
}
public ResponseModel FilterResponse(ResponseModel responseModel, RequestModel requestModel) => responseModel;
}
Map the WatchDog Services/UI in the endpoints
This will make the LogViewer available at /watchdog
app.UseEndpoints(endpoints => {
endpoints.MapControllers();
// map other needed things ...
endpoints.MapWatchDog();
});
Log Messages/Events
WatchLogger.Log("...TestGet Started...");
View Logs and Exception
Start your server and head to /watchdog
to view the logs.
Example: https://myserver.com/watchdog or https://localhost:[your-port]/watchdog
Still confused? Check out the implementation in the WatchDogCompleteApiNet6 folder.
Example Screens
Contribution
Feel like something is missing? Fork the repo and send a PR.
Encountered a bug? Fork the repo and send a PR.
Alternatively, open an issue and we'll get to it as soon as we can.
Credit
Original WatchDog.NET
Kelechi Onyekwere - Github Twitter
InterlockLedger.WatchDog
Rafael Monoman Teixeira - Github
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- InterlockLedger.Commons (>= 3.0.1)
- LiteDB (>= 5.0.12)
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Update/remove dependencies