![]() |
VOOZH | about |
dotnet add package Biss.MultiSinkLogger --version 2.0.0
NuGet\Install-Package Biss.MultiSinkLogger -Version 2.0.0
<PackageReference Include="Biss.MultiSinkLogger" Version="2.0.0" />
<PackageVersion Include="Biss.MultiSinkLogger" Version="2.0.0" />Directory.Packages.props
<PackageReference Include="Biss.MultiSinkLogger" />Project file
paket add Biss.MultiSinkLogger --version 2.0.0
#r "nuget: Biss.MultiSinkLogger, 2.0.0"
#:package Biss.MultiSinkLogger@2.0.0
#addin nuget:?package=Biss.MultiSinkLogger&version=2.0.0Install as a Cake Addin
#tool nuget:?package=Biss.MultiSinkLogger&version=2.0.0Install as a Cake Tool
O Biss.MultiSinkLogger é uma biblioteca desenvolvida para facilitar a gestão de logs em aplicações .NET. Este documento explica como configurar e usar o logger no cliente.
Adicione o Biss.MultiSinkLogger ao seu projeto via NuGet:
Install-Package Biss.MultiSinkLogger
Adicione o pacote Serilog e o pacote Serilog.AspNetCore:
Install-Package Serilog
Install-Package Serilog.AspNetCore
appsettings.jsonInclua as configurações do logger no arquivo appsettings.json:
{
"LoggerManagerSettings": {
"MinimumLevel": "Warning",
"OutputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}",
"Sinks": [
{
"Type": "Console",
"Active": true
},
{
"Type": "File",
"Active": true,
"Settings": {
"Path": "C:\\Logs\\",
"Filename": "log.txt",
"RollingInterval": "Day"
}
},
,
{
"Type": "SqlServer",
"Active": false,
"Settings": {
"ConnectionString": "Data Source=[server],[port];Persist Security Info=True;User ID=[user];Initial Catalog=[db];Password=[pwd];TrustServerCertificate=True;",
"TableName": "LogsTest"
}
},
{
"Type": "Sqlite",
"Active": false,
"Settings": {
"ConnectionString": "c:\\Temp\\LogDB\\Logs.db",
"TableName": "Logs"
}
},
{
"Type": "MongoDB",
"Active": false,
"Settings": {
"DatabaseUrl": "mongodb://[user@uri]/Logs",
"CollectionName": "Log",
"CappedMaxSizeMb": 1024,
"CappedMaxDocuments": 50000,
"RollingInterval": "Month"
}
},
{
"Type": "CosmosDB",
"Active": false,
"Settings": {
"EndpointUrl": "https://lab-logs.documents.azure.com:443/",
"AuthorizationKey": "[key]",
"DatabaseName": "[DbName]",
"ContainerName": "Logzis",
"PartitionKeyPath": "Application",
"TimeToLive": 7
}
},
{
"Type": "PostgreSql",
"Active": false,
"Settings": {
"NodeUris": ["http://localhost:9200"],
"IndexName": "logs",
"RollingInterval": "Day"
}
},
{
"Type": "MySql",
"Active": false,
"Settings": {
"ConnectionString": "Data Source=[server],[port];Persist Security Info=True;User ID=[user];Initial Catalog=[db];Password=[pwd];TrustServerCertificate=True;",
"TableName": "LogsTest"
}
},
{
"Type": "NewRelic",
"Active": false,
"Settings": {
"EndpointUrl": ["https://log-api.newrelic.com/log/v1"],
"ApplicationName": "[appName]",
"LicenseKey": "[licenseKey]",
"InsertKey": "[insertKey]",
"RollingInterval": "Day"
}
},
{
"Type": "RabbitMQ",
"Active": false,
"Settings": {
"HosrName": "http://localhost:5341",
"VirtualHost" = "/",
"QueueName" = "logs",
"UserName" = "guest",
"Password" = "guest"
"Port" = 5672",
"ExchangeName" = "logs",
}
},
{
"Type": "Sentry",
"Active": false,
"Settings": {
"Dsn": ["Dsn"],
"Environment": "Production",
"LogLevel": "Information"
}
},
{
"Type": "Slack",
"Active": false,
"Settings": {
"WebhookUrl": "http://localhost:5341",
"Channel": "#general",
"Username": "Logger",
"IconEmoji": ":robot_face:"
}
}
]
}
}
Program.csNo arquivo Program.cs, configure o logger:
using Biss.MultiSinkLogger;
using Biss.MultiSinkLogger.ExceptionHandlers;
using Biss.MultiSinkLogger.Http;
using Biss.MultiSinkLogger.Extensions;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// Inicializa o logger com configurações do appsettings.json
LoggingManager.InitializeLogger(builder.Configuration);
// Configura o Serilog
builder.Host.UseSerilog();
// Adiciona o HttpClient com o HttpLoggingHandler
builder.Services.AddTransient<HttpLoggingHandler>();
builder.Services.AddTransient<IExceptionHandler, DefaultExceptionHandler>();
var app = builder.Build();
// Middlewares para captura de logs
app.UseExceptionLogging();
app.UseCustomLogging();
app.Run();
Em controladores ou serviços, use o logger para registrar informações:
using Biss.MultiSinkLogger;
public class ExampleService
{
public void Process()
{
Logger.Info("Iniciando o processamento.");
try
{
// Lógica de negócio
}
catch (Exception ex)
{
Logger.Error("Erro durante o processamento.", ex);
}
}
}
Para capturar logs de chamadas HTTP:
using Biss.MultiSinkLogger.Http;
builder.Services.AddTransient<HttpLoggingHandler>();
builder.Services.AddHttpClient("ApiExterna")
.AddHttpMessageHandler<HttpLoggingHandler>();
Os logs serão registrados nos sinks configurados (console, arquivos, etc.). Certifique-se de validar se os arquivos estão sendo gerados no local configurado e que as permissões de escrita estão corretas.
Caso tenha problemas, consulte a documentação completa ou entre em contato com o suporte.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.0.0 | 110 | 4/22/2026 | |
| 1.1.2 | 358 | 12/7/2025 | |
| 1.1.0 | 615 | 12/7/2025 | 1.1.0 is deprecated because it is no longer maintained. |
| 1.0.1 | 617 | 1/27/2025 | 1.0.1 is deprecated because it is no longer maintained. |
| 1.0.0 | 571 | 1/26/2025 | 1.0.0 is deprecated because it is no longer maintained. |