Zacanbot.ElasticLogger 1.2.3

dotnet add package Zacanbot.ElasticLogger --version 1.2.3
                    
NuGet\Install-Package Zacanbot.ElasticLogger -Version 1.2.3
                    
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="Zacanbot.ElasticLogger" Version="1.2.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zacanbot.ElasticLogger" Version="1.2.3" />
                    
Directory.Packages.props
<PackageReference Include="Zacanbot.ElasticLogger" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zacanbot.ElasticLogger --version 1.2.3
                    
#r "nuget: Zacanbot.ElasticLogger, 1.2.3"
                    
#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.
#:package Zacanbot.ElasticLogger@1.2.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zacanbot.ElasticLogger&version=1.2.3
                    
Install as a Cake Addin
#tool nuget:?package=Zacanbot.ElasticLogger&version=1.2.3
                    
Install as a Cake Tool

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 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. 
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.2.3 695 7/12/2023
1.2.2 203 7/11/2023
1.2.1 214 7/3/2023
1.2.0 223 7/2/2023
1.1.1 182 7/2/2023
1.1.0 212 7/2/2023
1.0.3 187 7/1/2023
1.0.2 212 6/30/2023
1.0.1 197 6/30/2023
1.0.0 202 6/30/2023