DotGenie.Tracking.Monitoring
1.0.7
dotnet add package DotGenie.Tracking.Monitoring --version 1.0.7
NuGet\Install-Package DotGenie.Tracking.Monitoring -Version 1.0.7
<PackageReference Include="DotGenie.Tracking.Monitoring" Version="1.0.7" />
<PackageVersion Include="DotGenie.Tracking.Monitoring" Version="1.0.7" />
<PackageReference Include="DotGenie.Tracking.Monitoring" />
paket add DotGenie.Tracking.Monitoring --version 1.0.7
#r "nuget: DotGenie.Tracking.Monitoring, 1.0.7"
#:package DotGenie.Tracking.Monitoring@1.0.7
#addin nuget:?package=DotGenie.Tracking.Monitoring&version=1.0.7
#tool nuget:?package=DotGenie.Tracking.Monitoring&version=1.0.7
DotGenie.Tracking.Monitoring
A production-ready .NET monitoring package that sends logs and health signals from your app to a central Node.js monitoring service. It handles app-key auth automatically, runs background health checks, and provides simple APIs for logs and metrics.
π Getting Started - Get Your Application Key
To get your unique application key:
- π§ Email: mailstoumer@gmail.com
- π Dashboard: https://monitoring-dashboard-t3lc.onrender.com/
Your application key is required for authentication. Once you receive your key, you can start monitoring your application immediately.
β’ Target: .NET 6.0
β’ Transport: HTTPS JSON to your monitoring service base URL (default provided)
β’ Authentication: Application key automatically appended as ?key=...
What this package does
- Database health monitoring: lightweight connectivity checks every 5 minutes
- API health monitoring: pings your API health endpoints and measures latency
- Centralized logging: info/warning/error/debug + typed logs for DB/API health
- Error capture: middleware records unhandled exceptions and 4xx/5xx responses
- App-key management: your key is appended to every call; you never handle it manually
Install
dotnet add package DotGenie.Tracking.Monitoring
Quick start
π§ First: Request your application key from mailstoumer@gmail.com or visit https://monitoring-dashboard-t3lc.onrender.com/
- Configuration (appsettings.json)
{
"DotGenieMonitoring": {
"ApplicationKey": "your-app-key",
"ApplicationName": "My Awesome App",
"MonitoringServiceUrl": "https://monitoring-dashboard-t3lc.onrender.com/api/",
"ApiBaseUrl": "https://localhost:5001",
"HealthCheckIntervalMinutes": 5
}
}
- Register services (Program.cs)
using DotGenie.Tracking.Application.Api.Monitoring;
builder.Services.AddDotGenieMonitoring(builder.Configuration);
// Optional: Make DbContext available if you want DB health checks
builder.Services.AddScoped<DbContext>(sp => sp.GetRequiredService<YourDbContext>());
- (Optional) Use the middleware to capture API errors
app.UseMiddleware<ErrorLoggingMiddleware>();
Done. Health checks start automatically and logs/metrics go to your monitoring service with your key appended.
Components overview
MonitoringService
- Low-level HTTP client for the monitoring service
- Methods: SendLog, SendError, SendInfo, SendDatabaseStatus, SendApiHealth
- App key is appended via
?key=...automatically
SimpleMonitoringService (IHostedService, ISimpleMonitoringService)
- Runs periodic DB and API health checks on a timer
- Exposes methods: CheckDatabaseHealthAsync, CheckApiHealthAsync, SendApplicationMetricAsync
- Keeps last-known health status in memory and returns via getters
DbHealthMonitor (BackgroundService)
- Independent background worker that checks EF Core DbContext connectivity
- Sends
database_healthlogs via MonitoringService
ApiHealthMonitor (BackgroundService)
- Independent background worker that checks API endpoints (/health, /api/health, /api/status)
- Sends
api_healthspecialized logs and a general info/warning log with details - Detects DB root-cause from a health payload and switches category to "Database" when appropriate
ErrorLoggingMiddleware
- Captures unhandled exceptions and 4xx/5xx responses
- Sends structured logs with request details
MonitoringServiceExtensions
- Extension methods to register everything in one line:
AddDotGenieMonitoring(...)
- Extension methods to register everything in one line:
LogTypes
- Constants for safe log types accepted by the server: info, warning, error, debug, database_health, api_health
Public APIs
MonitoringService:
- Task SendLog(string type, string message, object? details = null)
- Task SendError(string message, Exception exception)
- Task SendInfo(string message, object? details = null)
- Task SendDatabaseStatus(bool isHealthy, string message, object? details = null)
- Task SendApiHealth(string url, string status, int responseTime, string message)
ISimpleMonitoringService:
- Task CheckDatabaseHealthAsync()
- Task CheckApiHealthAsync()
- Task SendApplicationMetricAsync(string metricType, string message, object? additionalData = null)
- Task<HealthStatus> GetDatabaseHealthStatusAsync()
- Task<HealthStatus> GetApiHealthStatusAsync()
- Task<OverallHealthStatus> GetOverallHealthStatusAsync()
Usage examples
Inject ISimpleMonitoringService into your controllers/services:
public class OrdersController : ControllerBase
{
private readonly ISimpleMonitoringService _monitoring;
public OrdersController(ISimpleMonitoringService monitoring) => _monitoring = monitoring;
[HttpPost("/orders")]
public async Task<IActionResult> Create([FromBody] CreateOrder req)
{
try
{
// ... your logic
await _monitoring.SendApplicationMetricAsync(
metricType: LogTypes.Info,
message: "Order created",
additionalData: new { orderId = 123, amount = 99.99 }
);
return Ok();
}
catch (Exception ex)
{
await _monitoring.SendApplicationMetricAsync(
metricType: LogTypes.Error,
message: $"Order failed: {ex.Message}",
additionalData: new { error = ex.Message }
);
throw;
}
}
}
Manually trigger health checks and read status:
await _monitoring.CheckDatabaseHealthAsync();
await _monitoring.CheckApiHealthAsync();
var overall = await _monitoring.GetOverallHealthStatusAsync();
Configuration
DotGenieMonitoring section in appsettings.json:
- ApplicationKey (required) β Your appβs key for the monitoring service
- ApplicationName β Human-friendly name (default: "Unknown Application")
- MonitoringServiceUrl β Base URL for the monitoring API (default provided)
- ApiBaseUrl β Your API base used by health checks (if provided)
- HealthCheckIntervalMinutes β Period for SimpleMonitoringService checks (default: 5)
- EnableDatabaseMonitoring β true/false (default: true)
- EnableApiMonitoring β true/false (default: true)
- HealthCheckTimeoutSeconds β timeout for health requests (default: 30)
Environment variables:
- DOTGENIE_MONITORING__APPLICATIONKEY, DOTGENIE_MONITORING__APPLICATIONNAME, DOTGENIE_MONITORING__MONITORINGSERVICEURL, DOTGENIE_MONITORING__APIBASEURL, etc.
Payloads (to /api/logs)
All logs are posted as JSON to {MonitoringServiceUrl}/logs?key={ApplicationKey}
Common envelope:
- type: string (see LogTypes)
- message: string
- details: object or null
- timestamp: ISO-8601 string
- source: "ApplicationApi"
- environment: value of ASPNETCORE_ENVIRONMENT or "Unknown"
Examples:
- database_health
- message: "Database is healthy"
- details: { isHealthy: true, additionalInfo: { ... } }
- api_health
- message: "API health check passed"
- details: { url, status, responseTime, source, environment }
Notes on metric types
When calling SendApplicationMetricAsync(metricType, ...), use supported types:
- info, warning, error, debug, database_health, api_health
If a different value is provided (e.g., "order_created"), the client falls back to info and includes your original value at details.originalMetricType so your event is still visible.
Troubleshooting
- Not seeing logs? Check application logs for lines starting with "Failed to send monitoring log"βthey include status code and server response.
- 404 on API health? The package posts API health via /api/logs (type: api_health). Ensure your Node app handles that type.
- Key rejected? Verify the
ApplicationKeymatches the one registered in your monitoring service. Contact mailstoumer@gmail.com if you need a new key. - Health URL wrong? Set
ApiBaseUrlor setApiHealthMonitor:BaseUrlif you're using ApiHealthMonitor directly. - Need help? Email mailstoumer@gmail.com or visit https://monitoring-dashboard-t3lc.onrender.com/
Security
- Connection strings are never sent; DB details are sanitized
- All calls use HTTPS (when your MonitoringServiceUrl uses https)
- Errors are logged but do not crash your app (graceful degradation)
Support & Dashboard
π§ Get Your App Key: mailstoumer@gmail.com
π Monitoring Dashboard: https://monitoring-dashboard-t3lc.onrender.com/
π Integration Guide: see INTEGRATION_GUIDE.md
π Issues: https://github.com/Herofab/MonitoringSoftwaresNuget
β Happy monitoring!
| 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.EntityFrameworkCore (>= 6.0.10)
- Microsoft.Extensions.Configuration.Abstractions (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.1)
- Microsoft.Extensions.Http (>= 6.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 6.0.0)
- System.Text.Json (>= 6.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.