LoggerBot 1.6.0
dotnet add package LoggerBot --version 1.6.0
NuGet\Install-Package LoggerBot -Version 1.6.0
<PackageReference Include="LoggerBot" Version="1.6.0" />
<PackageVersion Include="LoggerBot" Version="1.6.0" />
<PackageReference Include="LoggerBot" />
paket add LoggerBot --version 1.6.0
#r "nuget: LoggerBot, 1.6.0"
#:package LoggerBot@1.6.0
#addin nuget:?package=LoggerBot&version=1.6.0
#tool nuget:?package=LoggerBot&version=1.6.0
LoggerBot
Telegram bot orqali ASP.NET Core ilovalardan log yuborish uchun NuGet paket. v1.6.0 — IOptions<LoggerBotOptions>, IHttpClientFactory, va multi-target net6-10.
Quick install
dotnet add package LoggerBot --version 1.6.0
Targets
net6.0 / net7.0 / net8.0 / net9.0 / net10.0
Configuration
appsettings.json ichida LoggerBot sectionini to'ldiring:
{
"LoggerBot": {
"Token": "123456:bot-token",
"ChatId": -100123456789
}
}
Section nomi LoggerBotOptions.SectionName ("LoggerBot") orqali default keladi; options overload bilan o'zingiz qayta belgilashingiz mumkin.
Registration (recommended — IOptions<LoggerBotOptions>)
// appsettings.json'dan bind:
builder.Services.AddLoggerBot();
// yoki dasturiy ravishda:
builder.Services.AddLoggerBot(o =>
{
o.Token = "123456:bot-token";
o.ChatId = -100123456789;
});
Ikkala overload ham LoggerBotOptions, named HttpClient ("LoggerBot") va ILoggerService singletonni ro'yxatga oladi.
Usage
ILoggerService ni controller yoki handlerga inject qiling. Har bir metod CancellationToken qabul qiladi va u botClient.SendTextMessageAsync ga uzatiladi.
using LoggerBot.Services;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
private readonly ILoggerService _logger;
public OrdersController(ILoggerService logger) => _logger = logger;
[HttpPost]
public async Task<IActionResult> Create(CancellationToken ct)
{
await _logger.InfoAsync("Order create boshlandi", cancellationToken: ct);
try
{
// ... biznes logikasi
await _logger.SuccessAsync("Order yaratildi", cancellationToken: ct);
await _logger.MessageAsync("Audit: yangi buyurtma", cancellationToken: ct);
await _logger.WarningAsync("Stok kam qoldi", cancellationToken: ct);
return Ok();
}
catch (Exception ex)
{
await _logger.ErrorAsync(ex, detailed: true, cancellationToken: ct);
var dump = System.Text.Encoding.UTF8.GetBytes(ex.ToString());
await _logger.ErrorAttachmentAsync("Order yaratishda xatolik", dump, cancellationToken: ct);
return StatusCode(500);
}
}
}
Legacy API (deprecated)
Eski LoggerService(IConfiguration, IHostEnvironment) konstruktori [Obsolete] deb belgilangan. Yangi konstruktor IOptions<LoggerBotOptions> qabul qiladi — DI orqali avtomatik chaqiriladi. Iltimos IOptions<LoggerBotOptions> ga ko'chib o'ting.
What's new in 1.6.0
- Multi-target:
net6.0/net7.0/net8.0/net9.0/net10.0 - Strongly-typed
LoggerBotOptions(Token,ChatId,SectionName) IHttpClientFactoryorqali namedHttpClient("LoggerBot") —TelegramBotClientshu HttpClient ustida ishlaydiInterlocked.CompareExchangebilan race-free queue worker — aniq bitta worker ishga tushadiCancellationTokenbutun yo'l bo'ylabbotClient.SendTextMessageAsyncga uzatiladiConsole.WriteLineolib tashlandi — agar inject qilingan bo'lsaILogger<LoggerService>ishlatiladi
Multi-project chats
Bir nechta loyihaga (chatga) yozish kerak bo'lsa, appsettings.json ga qo'shimcha kalitlar qo'shing va metod chaqirig'ida projectName bering:
{
"LoggerBot": {
"Token": "bot-token",
"ChatId": -100default,
"Project1": -100chatId1,
"Project2": -100chatId2
}
}
await _logger.ErrorAsync(exception, "Project1", detailed: true, cancellationToken: ct);
License / contributing
Issue va PR'lar ochiq — https://github.com/nbk-bot/LoggerBot. Litsenziya repo ildizidagi LICENSE fayliga muvofiq.
| 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 is compatible. 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 is compatible. 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 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.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Telegram.Bot (>= 19.0.0)
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Telegram.Bot (>= 19.0.0)
-
net7.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Telegram.Bot (>= 19.0.0)
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Telegram.Bot (>= 19.0.0)
-
net9.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Telegram.Bot (>= 19.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on LoggerBot:
| Package | Downloads |
|---|---|
|
GlobalErrorHandler
Middleware for global exception handling in ASP.NET Core. Pluggable IErrorHandlerSink lets you opt in to Telegram delivery via LoggerBot or ship reports anywhere else. |
GitHub repositories
This package is not used by any popular GitHub repositories.