LogCenter.Logger
1.0.2
dotnet add package LogCenter.Logger --version 1.0.2
NuGet\Install-Package LogCenter.Logger -Version 1.0.2
<PackageReference Include="LogCenter.Logger" Version="1.0.2" />
<PackageVersion Include="LogCenter.Logger" Version="1.0.2" />
<PackageReference Include="LogCenter.Logger" />
paket add LogCenter.Logger --version 1.0.2
#r "nuget: LogCenter.Logger, 1.0.2"
#:package LogCenter.Logger@1.0.2
#addin nuget:?package=LogCenter.Logger&version=1.0.2
#tool nuget:?package=LogCenter.Logger&version=1.0.2
LogCenter.Logger
This package helps you send logs from a .NET console application to LogCenter using the standard ILogger abstraction.
See: https://github.com/hudsonventura/LogCenter
Getting Started
Install the package:
dotnet add package Microsoft.Extensions.Logging.Console && \
dotnet add package LogCenter.Logger
Basic Setup
The example below is based on examples/dotnet/Program.cs.
using LogCenter;
using Microsoft.Extensions.Logging;
var drain = new LogCenterDrain();
using var loggerFactory = LoggerFactory.Create(builder =>
{
builder.ClearProviders();
builder.AddLogCenter(
new LogCenterOptions
{
// LogCenter's URL
url = "http://localhost:9200",
// Table name
table = "example_interceptor",
// Generate this on LogCenter inteface, on you profile photo.
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
// The timeout to send the log and data to LogCenter
Timeout = 5000
},
drain);
});
var logger = loggerFactory.CreateLogger<Program>();
Logging Messages
After configuring the provider, use ILogger exactly as you normally would in a console application:
var test = new
{
nome = "John Doe Jr. da Silva",
idade = 30,
email = "john.doe.jr@example.com"
};
logger.LogInformation("Dados do usuário {@user}", test);
logger.LogDebug("Hello World - Debug");
logger.LogInformation("Hello World - Information");
logger.LogWarning("Hello World - Warning");
logger.LogError("Hello World - Error");
logger.LogCritical("Hello World - Critical");
Unhandled Exceptions
For console applications, you can log an unhandled exception and wait for the HTTP send to finish before shutdown. The the drain at line var drain = new LogCenterDrain(); and used after, is going to guarantee this functionality.
Structured Logging
LogCenter.Logger supports structured logging with message templates.
Example:
var user = new
{
nome = "John Doe Jr. da Silva",
idade = 30,
email = "john.doe.jr@example.com"
};
logger.LogInformation("User data {@user}", user);
Tags
LogCenter.Logger supports tags. Use:
Example:
var tags = new string[] {"tag 1", "tag 2", "whatever"}
//or
var tags = new List<string> {"tag 1", "tag 2", "whatever"}
//MUST BE "_tags_"
logger.LogInformation("User data {@user} {@_tags_}", user, tags);
This sends:
- the rendered message
- the log level
- timestamp
- trace information when available
- structured properties as JSON
That makes the data readable in LogCenter and also searchable as JSON.
Notes
- The package works with the normal
ILoggerAPI. - Logs are sent over HTTP to LogCenter.
- Structured objects are serialized and stored in a JSON-friendly way.
- This package is a good fit for console apps, workers, background services, and other non-ASP.NET processes.
Build
To build the NuGet package locally:
dotnet pack src/libs/nuget/Logger/Logger.csproj -c Release
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.6)
- Microsoft.Extensions.Logging (>= 10.0.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LogCenter.Logger:
| Package | Downloads |
|---|---|
|
LogCenter.RequestLogger
Send the request, response and logs to LogCenter. Handles logging and message exchange efficiently. |
GitHub repositories
This package is not used by any popular GitHub repositories.