WatchDog.NET
1.4.10
Prefix Reserved
See the version list below for details.
dotnet add package WatchDog.NET --version 1.4.10
NuGet\Install-Package WatchDog.NET -Version 1.4.10
<PackageReference Include="WatchDog.NET" Version="1.4.10" />
paket add WatchDog.NET --version 1.4.10
#r "nuget: WatchDog.NET, 1.4.10"
// Install WatchDog.NET as a Cake Addin #addin nuget:?package=WatchDog.NET&version=1.4.10 // Install WatchDog.NET as a Cake Tool #tool nuget:?package=WatchDog.NET&version=1.4.10
WatchDog
Introduction
WatchDog is a Realtime Message, Event, HTTP (Request & Response) and Exception logger and viewer for ASP.Net Core 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 with the option of using your external databases (MSSQL, MySQl, Postgres, MongoDB).
General Features
- RealTime HTTP Request, Response, and 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
What's New
- Security Optimization
- Query Filters Fixes and Optimizations
- Package Assembly as DB Name Fix(MongoDB)
Breaking Changes
- SqlDriverOption is now DbDriverOption (>= 1.4.0)
Support
- .NET Core 3.1 and newer
Installation
Install via .NET CLI
dotnet add package WatchDog.NET --version 1.4.10
Install via Package Manager
Install-Package WatchDog.NET --version 1.4.10
Usage
To enable WatchDog to listen for requests, use the WatchDog middleware provided by WatchDog.
Add WatchDog Namespace in Startup.cs
using WatchDog;
Register WatchDog service in Startup.cs
under ConfigureService()
services.AddWatchDogServices();
Setup AutoClear Logs Optional
This clears the logs after a specific duration.
NOTE When
IsAutoClear = true
Default Schedule Time is set to Weekly, override the settings like below:
services.AddWatchDogServices(opt =>
{
opt.IsAutoClear = true;
opt.ClearTimeSchedule = WatchDogAutoClearScheduleEnum.Monthly;
});
Setup Logging to External Db (MSSQL, MySQL, PostgreSQL & MongoDb) Optional
Add Database Connection String and Choose DbDriver Option
services.AddWatchDogServices(opt =>
{
opt.IsAutoClear = false;
opt.SetExternalDbConnString = "Server=localhost;Database=testDb;User Id=postgres;Password=root;";
opt.DbDriverOption = WatchDogSqlDriverEnum.PostgreSql;
});
Add WatchDog middleware in the HTTP request pipeline in Startup.cs
under Configure()
NOTE Add Authentication option like below:
Important
This authentication information (Username and Password) will be used to access the log viewer.
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
});
NOTE If your project uses authentication, then
app.UseWatchDog();
should come after app.UseRouting(), app.UseAuthentication(), app.UseAuthorization(), in that order
Optional Configurations: Optional
- Blacklist: List of routes, paths or endpoints to be ignored (should be a comma separated string like below).
- Serializer: If not default, specify the type of global json serializer/converter used
- CorsPolicy: Policy Name if project uses CORS
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
//Optional
opt.Blacklist = "Test/testPost, api/auth/login"; //Prevent logging for specified endpoints
opt.Serializer = WatchDogSerializerEnum.Newtonsoft; //If your project use a global json converter
opt.CorsPolicy = "MyCorsPolicy"
});
Add WatchDog Exception Logger Optional
This is used to log in-app exceptions that occur during a particular HTTP request.
NOTE Add Exception Logger before the main WatchDog Middleware, preferably at the top of the middleware hierarchy so as to catch possible early exceptions.
app.UseWatchDogExceptionLogger();
...
app.UseWatchDog(opt =>
{
opt.WatchPageUsername = "admin";
opt.WatchPagePassword = "Qwerty@123";
...
});
Log Messages/Events
WatchLogger.Log("...Test Log...");
WatchLogger.LogWarning(JsonConvert.Serialize(model));
WatchLogger.LogError(res.Content, eventId: reference);
Sink Logs from ILogger
You can also sink logs from the .NET ILogger into WatchDog
For .NET 6 and above
builder.Logging.AddWatchDogLogger();
For .NET Core 3.1, configure logging and add .AddWatchDogLogger()
to the CreateHostBuilder
method of the Program.cs
class
Host.CreateDefaultBuilder(args)
.ConfigureLogging( logging =>
{
logging.AddWatchDogLogger();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
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 WatchDogCompleteTestAPI folder or the .NET 6 implementation in the WatchDogCompleteApiNet6 folder.
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
Kelechi Onyekwere - Github Twitter
Official Documentation
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Dapper (>= 2.0.123)
- LiteDB (>= 5.0.11)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc (>= 2.2.0)
- Microsoft.AspNetCore.SignalR (>= 1.1.0)
- Microsoft.AspNetCore.SignalR.Core (>= 1.1.0)
- Microsoft.AspNetCore.StaticFiles (>= 2.2.0)
- Microsoft.Extensions.FileProviders.Abstractions (>= 3.1.22)
- Microsoft.Extensions.FileProviders.Embedded (>= 3.1.22)
- Microsoft.Extensions.FileProviders.Physical (>= 3.1.22)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.22)
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.0)
- MongoDB.Driver (>= 2.18.0)
- MySql.Data (>= 8.0.29)
- Newtonsoft.Json (>= 13.0.1)
- Npgsql (>= 5.0.0 && <= 5.0.10)
- System.Data.SqlClient (>= 4.8.5)
-
net6.0
- Dapper (>= 2.0.123)
- LiteDB (>= 5.0.11)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc (>= 2.2.0)
- Microsoft.AspNetCore.SignalR (>= 1.1.0)
- Microsoft.AspNetCore.SignalR.Core (>= 1.1.0)
- Microsoft.AspNetCore.StaticFiles (>= 2.2.0)
- Microsoft.Extensions.FileProviders.Abstractions (>= 3.1.22)
- Microsoft.Extensions.FileProviders.Embedded (>= 3.1.22)
- Microsoft.Extensions.FileProviders.Physical (>= 3.1.22)
- Microsoft.Extensions.Logging.Abstractions (>= 3.1.22)
- Microsoft.IO.RecyclableMemoryStream (>= 2.2.0)
- MongoDB.Driver (>= 2.18.0)
- MySql.Data (>= 8.0.29)
- Newtonsoft.Json (>= 13.0.1)
- Npgsql (>= 6.0.4)
- System.Data.SqlClient (>= 4.8.5)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on WatchDog.NET:
Package | Downloads |
---|---|
GuoKun.CPS
国坤CPS库 |
|
LC.Web.Base
LC.Web.Base |
|
Chaosage.Core.Setup
Chaosage开发平台API配置规范 |
|
Szyj.MicroService.Api.Basic
尚哲医健微服务api.host基架,去掉 Abp.Autofac |
|
PluginCore.Plugins.WatchDogPlugin
PluginCore Plugins: WatchDogPlugin |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.4.11 | 15,109 | 3/31/2024 | |
1.4.10 | 32,357 | 5/19/2023 | |
1.4.7 | 5,635 | 4/19/2023 | |
1.4.6 | 22,762 | 2/16/2023 | |
1.4.3 | 11,713 | 2/1/2023 | |
1.4.2 | 3,924 | 1/18/2023 | |
1.4.1 | 1,226 | 1/17/2023 | |
1.4.0 | 1,706 | 1/16/2023 | |
1.3.3 | 13,403 | 12/14/2022 | |
1.3.3-rc | 1,496 | 11/7/2022 | |
1.3.2 | 24,952 | 9/18/2022 | |
1.3.1 | 5,983 | 8/9/2022 | |
1.3.0 | 3,247 | 7/19/2022 | |
1.2.1 | 4,784 | 6/7/2022 | |
1.2.0 | 1,585 | 5/15/2022 | |
1.1.0 | 2,389 | 4/30/2022 | |
1.0.2 | 1,160 | 4/30/2022 | |
1.0.1 | 1,193 | 4/30/2022 | |
1.0.0 | 1,196 | 4/29/2022 |
- Security Optimization
- Query Filters Fixes and Optimizations
- Package Assembly as DB Name Fix(MongoDB)