Diffancy.WatchDog.NET 1.35.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Diffancy.WatchDog.NET --version 1.35.0                
NuGet\Install-Package Diffancy.WatchDog.NET -Version 1.35.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Diffancy.WatchDog.NET" Version="1.35.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Diffancy.WatchDog.NET --version 1.35.0                
#r "nuget: Diffancy.WatchDog.NET, 1.35.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Diffancy.WatchDog.NET as a Cake Addin
#addin nuget:?package=Diffancy.WatchDog.NET&version=1.35.0

// Install Diffancy.WatchDog.NET as a Cake Tool
#tool nuget:?package=Diffancy.WatchDog.NET&version=1.35.0                

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 MSSQL, MySQl or Postgres databases.

Request & Response Viewer

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

What's New

  • In-code logger for messages and events

Fixes

  • Fixed Middleware order
  • Fixed Index pages not showing on MVC Apps

Support

  • .NET Core 3.1 and newer

Installation

Install via .NET CLI

dotnet add package WatchDog.NET --version 1.3.0

Install via Package Manager

Install-Package WatchDog.NET --version 1.3.0

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.

services.AddWatchDogServices(opt => 
{ 
   opt.IsAutoClear = true; 
});

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) Optional

Add Database Connection String and Choose SqlDriver Option

services.AddWatchDogServices(opt => 
{
   opt.IsAutoClear = false; 
   opt.SetExternalDbConnString = "Server=localhost;Database=testDb;User Id=postgres;Password=root;"; 
   opt.SqlDriverOption = WatchDogSqlDriverEnum.PostgreSql; 
});

Add WatchDog middleware in the HTTP request pipeline in Startup.cs under Configure()

Login page sample

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 projects startup or program class contains app.UseMvc() or app.UseRouting() then app.UseWatchDog() should come after Important If your projects startup or program class contains app.UseEndpoints() then app.UseWatchDog() should come before Important

Request and Response Sample Details

Add list of routes you want to ignore by the logger: Optional

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";
 });
Add WatchDog Exception Logger Optional

This is used to log in-app exceptions that occur during a particular HTTP request.

Exception Sample Details

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"; 
   opt.Blacklist = "Test/testPost, weatherforecast";
 });

Log Messages/Events

WatchLogger.Log("...TestGet Started...");

In-code log messages

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

Israel Ulelu - Github Twitter

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.37.0 355 2/25/2023
1.36.0 251 2/25/2023
1.35.0 327 1/16/2023
1.34.0 365 1/2/2023

- In-code logger for message and events