.NET SDK
Install the Logdash .NET SDK, send your first log and your first metric.
Install the package, paste your API key and the first log lands in the dashboard within a second. Everything below is copied from the .NET SDK README.
Install
dotnet add package Logdash Initialise
Create a project in Logdash, copy its API key and keep it in an environment variable. The key identifies the project the data lands in.
using Logdash;
using Logdash.Models;
var apiKey = Environment.GetEnvironmentVariable("LOGDASH_API_KEY");
var (logdash, metrics) = new LogdashBuilder()
.WithHttpClient(new HttpClient())
.WithInitializationParams(new InitializationParams(apiKey))
.Build(); Send a log
logdash.Info("This is info message");
logdash.Warn("This is warn message");
logdash.Error("This is an error message");
logdash.Debug("This is a debug message"); Send a metric
Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.
// to set absolute value
metrics.Set("key", 2);
// or increment / decrement by
metrics.Mutate("key", 3); Works with
- ASP.NET Core
- Minimal APIs
- Worker Services
- Blazor
- Console apps
FAQ
How do I register it in ASP.NET Core?
Call `builder.Services.AddLogdash(new InitializationParams(apiKey))`, then take `ILogdashLogger` and `ILogdashMetrics` as constructor parameters in your controllers and services.
Can I use it without dependency injection?
Yes. `new LogdashBuilder().WithHttpClient(...).WithInitializationParams(...).Build()` returns a logger and a metrics client as a tuple.
What happens if I leave the API key out?
Logs go to the local console only. There is also a `host` parameter if you are running a self-hosted Logdash, and `verbose` if you need to debug the SDK itself.