Zacanbot.ElasticLogger
1.2.3
dotnet add package Zacanbot.ElasticLogger --version 1.2.3
NuGet\Install-Package Zacanbot.ElasticLogger -Version 1.2.3
<PackageReference Include="Zacanbot.ElasticLogger" Version="1.2.3" />
<PackageVersion Include="Zacanbot.ElasticLogger" Version="1.2.3" />
<PackageReference Include="Zacanbot.ElasticLogger" />
paket add Zacanbot.ElasticLogger --version 1.2.3
#r "nuget: Zacanbot.ElasticLogger, 1.2.3"
#:package Zacanbot.ElasticLogger@1.2.3
#addin nuget:?package=Zacanbot.ElasticLogger&version=1.2.3
#tool nuget:?package=Zacanbot.ElasticLogger&version=1.2.3
Dotnet Elasticsearch and Console Logger
A simple and easy-to-use implementation of the standard Microsoft.Logging.Extentions.ILogger
interface that outputs to Console and Elasticsearch. It logs UTC timestamps instead of local time.
Elasticsearch needs to be installed with TLS security enabled (the default since v8). This library uses the default user elastic
to connect. Get an Elasticsearch instance started easily with Docker Compose by following the official guide here: https://www.elastic.co/blog/getting-started-with-the-elastic-stack-and-docker-compose.
Example usage in an ASP.Net app
Register the logger in Program.cs (or Startup.cs):
using Zacanbot.ElasticLogger;
var builder = WebApplication.CreateBuilder(args);
// Add Elasticsearch and Console logger
builder.Logging.ClearProviders();
builder.Logging.AddElasticLogger(config =>
{
config.ElasticUrl = "https://localhost:9200";
config.ElasticPassword = "elastic";
config.DefaultIndex = "aspnet_logs";
});
Use it like any other ILogger in your controller:
public class MyController : ControllerBase
{
private readonly ILogger<MyController> _logger;
public MyController(ILogger<MyController> logger)
{
_logger = logger;
}
[HttpGet("PingHello")]
public string PingHello()
{
_logger.LogInformation("Received a Ping request");
return "hello";
}
}
Example usage in a Console app (Factory method)
using Microsoft.Extensions.Logging;
using Zacanbot.ElasticLogger;
var logger = LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.SetMinimumLevel(LogLevel.Debug);
builder.AddElasticLogger(config =>
{
config.ElasticUrl = "https://localhost:9200";
config.ElasticPassword = "elastic";
config.DefaultIndex = "test_logs";
});
}).CreateLogger("Program");
logger.LogInformation("Info Log");
logger.LogWarning("Warning Log");
logger.LogError("Error Log");
logger.LogCritical("Critical Log");
Console.WriteLine("\nPress any key to exit");
Console.ReadLine();
Example usage in a Console app (Host with DI method)
using Zacanbot.ElasticLogger;
var host = Host.CreateDefaultBuilder(args)
.ConfigureLogging((_, logging) =>
{
logging.ClearProviders();
logging.AddElasticLogger(config =>
{
config.ElasticUrl = "https://localhost:9200";
config.ElasticPassword = "elastic";
config.DefaultIndex = "test_logs";
});
});
var app = host.Build();
ILogger? logger = app.Services.GetService<ILogger<Program>>();
if (logger != null)
{
logger.LogInformation("Info Log");
logger.LogWarning("Warning Log");
logger.LogError("Error Log");
logger.LogCritical("Critical Log");
}
Console.WriteLine("\nPress any key to exit");
Console.ReadLine();
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 is compatible. 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
- Elastic.Clients.Elasticsearch (>= 8.1.1)
- Microsoft.Extensions.Logging (>= 7.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
-
net7.0
- Elastic.Clients.Elasticsearch (>= 8.1.1)
- Microsoft.Extensions.Logging (>= 7.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 7.0.0)
- Microsoft.Extensions.Options (>= 7.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.