Watchlog.Metric
1.0.0
dotnet add package Watchlog.Metric --version 1.0.0
NuGet\Install-Package Watchlog.Metric -Version 1.0.0
<PackageReference Include="Watchlog.Metric" Version="1.0.0" />
<PackageVersion Include="Watchlog.Metric" Version="1.0.0" />
<PackageReference Include="Watchlog.Metric" />
paket add Watchlog.Metric --version 1.0.0
#r "nuget: Watchlog.Metric, 1.0.0"
#:package Watchlog.Metric@1.0.0
#addin nuget:?package=Watchlog.Metric&version=1.0.0
#tool nuget:?package=Watchlog.Metric&version=1.0.0
Watchlog.Metric (.NET Client)
🔗 Website: https://watchlog.io
Watchlog.Metric is a lightweight and non-blocking .NET client for sending custom metrics to your Watchlog server.
📦 Installation
Install the package via NuGet:
dotnet add package Watchlog.Metric
🚀 Quick Start
1. Import the namespace
using WatchlogMetric;
2. Create an instance of the Watchlog client
var watchlog = new WatchlogClient(); // No configuration needed
3. Send metrics
watchlog.Increment("user_login", 1);
watchlog.Decrement("cart_items", 2);
watchlog.Gauge("active_users", 120);
watchlog.Percentage("disk_usage", 73.5);
watchlog.SystemByte("memory_usage", 1048576);
All operations are asynchronous, non-blocking, and fail-safe — they never throw exceptions or print logs.
🐳 Docker Setup
When running your .NET app in Docker, you can specify the agent URL explicitly:
using WatchlogMetric;
// Create client with explicit agent URL for Docker
var watchlog = new WatchlogClient("http://watchlog-agent:3774");
watchlog.Increment("user_login", 1);
Docker Compose Example:
version: '3.8'
services:
watchlog-agent:
image: watchlog/agent:latest
container_name: watchlog-agent
ports:
- "3774:3774"
environment:
- WATCHLOG_APIKEY=your-api-key
- WATCHLOG_SERVER=https://log.watchlog.ir
networks:
- app-network
dotnet-app:
build: .
container_name: dotnet-app
ports:
- "5000:5000"
depends_on:
- watchlog-agent
networks:
- app-network
networks:
app-network:
driver: bridge
Docker Run Example:
# 1. Create network
docker network create app-network
# 2. Run Watchlog Agent
docker run -d \
--name watchlog-agent \
--network app-network \
-p 3774:3774 \
-e WATCHLOG_APIKEY="your-api-key" \
-e WATCHLOG_SERVER="https://log.watchlog.ir" \
watchlog/agent:latest
# 3. Run .NET app (make sure your code uses new WatchlogClient("http://watchlog-agent:3774"))
docker run -d \
--name dotnet-app \
--network app-network \
-p 5000:5000 \
my-dotnet-app
🔍 Environment Detection
The package automatically detects the runtime environment:
- Local / non-K8s:
http://127.0.0.1:3774 - Kubernetes:
http://watchlog-node-agent.monitoring.svc.cluster.local:3774
Manual Override: You can override the endpoint by passing agentUrl parameter to the constructor:
var watchlog = new WatchlogClient("http://watchlog-agent:3774"); // Custom agent URL
Important Notes:
- When using Docker, use the container name as the hostname (e.g.,
watchlog-agent) - Both containers must be on the same Docker network
- The agent must be running before your app starts
- If
agentUrlis not provided, auto-detection will be used (local or Kubernetes)
🛡️ Features
- ✔️ Fully async-safe using
Task.Run - ✔️ No logs, no exceptions
- ✔️ Tiny footprint, pure .NET
- ✔️ Works in ASP.NET Core, background services, or console apps
💡 Example: ASP.NET Core Integration
public class HomeController : Controller
{
private readonly WatchlogClient _watchlog = new WatchlogClient();
public IActionResult Index()
{
_watchlog.Increment("homepage_visits");
return View();
}
}
📄 License
MIT License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.