X.Extensions.Logging.Telegram
2.0.0-beta
Prefix Reserved
See the version list below for details.
dotnet add package X.Extensions.Logging.Telegram --version 2.0.0-beta
NuGet\Install-Package X.Extensions.Logging.Telegram -Version 2.0.0-beta
<PackageReference Include="X.Extensions.Logging.Telegram" Version="2.0.0-beta" />
paket add X.Extensions.Logging.Telegram --version 2.0.0-beta
#r "nuget: X.Extensions.Logging.Telegram, 2.0.0-beta"
// Install X.Extensions.Logging.Telegram as a Cake Addin #addin nuget:?package=X.Extensions.Logging.Telegram&version=2.0.0-beta&prerelease // Install X.Extensions.Logging.Telegram as a Cake Tool #tool nuget:?package=X.Extensions.Logging.Telegram&version=2.0.0-beta&prerelease
Telegram logging extensions
- X.Extensions.Logging.Telegram
- X.Extensions.Serilog.Sinks.Telegram
Telegram logging providers for Serilog and standard .NET logging.
What is Telegram?
What is Telegram? What do I do here? Telegram is a messaging app with a focus on speed and security, itβs super-fast, simple and free. You can use Telegram on all your devices at the same time β your messages sync seamlessly across any number of your phones, tablets or computers. Telegram has over 500 million monthly active users and is one of the 10 most downloaded apps in the world.
Why you need write logs to Telegram?
Because it very comfortable - you can receive important messages directly to your smartphone or laptop.
Prepare Telegram bot
For sending log messages into telegram channel or chat you need create telegram bot before. Here you can find how to do it. After you created bot add it to channel with admin role and allow bot to post messages.
Prepare Telegram channel
In telegram there are two types of channels: public and private. For public channel you can use channel name as ChatId in configuration.
For private channel you can use @JsonDumpBot to get private channel id. Just forward any message from private channelto this bot. Additional information you can find here.
Do not forget to add your bot as admin with write messages permission to channel.
X.Extensions.Logging.Telegram
X.Extensions.Logging.Telegram is logging provider for standard .NET logging.
Getting Started
You can configure Telegram logging provider by code or by config file:
var options = new TelegramLoggerOptions(LogLevel.Information)
{
AccessToken = "1234567890:AAAaaAAaa_AaAAaa-AAaAAAaAAaAaAaAAAA",
ChatId = "-0000000000000",
Source = "Human Readable Project Name"
};
...
builder
.ClearProviders()
.AddTelegram(options)
.AddConsole();
appconfig.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Telegram": {
"LogLevel": {
"Default": "Error",
"WebApp.Controllers": "Warning"
},
"AccessToken": "1234567890:AAAaaAAaa_AaAAaa-AAaAAAaAAaAaAaAAAA",
"ChatId": "1234567890",
"Source": "Human Readable Project Name"
}
},
"AllowedHosts": "*"
}
and pass IConfiguration object to extensions method
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureLogging((context, builder) =>
{
if (context.Configuration != null)
builder
.AddTelegram(context.Configuration)
.AddConsole();
})
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
Use custom log writer
Now developers can use their own implementation for writing data to Telegram. Custom writer should implement ILogWriter interface:
var customLogWriter = new CustomLogWriter();
logBuilder.AddTelegram(options, customLogWriter);
Use custom message formatter
For implement custom message formatting ITelegramMessageFormatter can be used now.
private ITelegramMessageFormatter CreateFormatter(string name)
{
return new CustomTelegramMessageFormatter(name);
}
logBuilder.AddTelegram(options, CreateFormatter);
For using custom message formatter delegate Func<string, ITelegramMessageFormatter> should be passed to extensions method AddTelegram. Delegate should be used because formatter needs to know which category is used for rendering the message.
X.Extensions.Serilog.Sinks.Telegram
X.Serilog.Sinks.Telegram is an open-source Serilog sink that allows you to send log events to Telegram. It's a convenient way to integrate Telegram as a logging output, enabling you to receive important log information directly in your chat.
Features
Real-time Logging: The sink offers the ability to send log events to a Telegram channel in real-time, ensuring that you can stay up-to-date with your application's behavior and any issues as they arise.
Customizable Formatting: You can configure the format of log messages sent to the Telegram channel, allowing you to tailor them to your preferences and specific requirements.
Filtering: The sink supports filtering log events before they are dispatched to the Telegram channel, ensuring that only pertinent information is shared.
Asynchronous Sending: Log events are sent asynchronously to the Telegram channel, minimizing potential impact on your application's performance.
Easy Configuration: Configuring the sink to work with your Telegram channel is straightforward, and you can find comprehensive information in the Configuration Wiki.
Getting Started
To begin using the X.Serilog.Sinks.Telegram sink, follow these steps:
- Install the Package: You can install the sink package from NuGet using the following command:
dotnet add package X.Serilog.Sinks.Telegram
- Configure the Sink: Set up the Telegram sink with the appropriate settings in your application's configuration. Here's an example configuration in C#:
Log.Logger = new LoggerConfiguration()
.WriteTo.TelegramCore(
token: botToken,
chatId: loggingChatId,
logLevel: LogEventLevel.Verbose)
.WriteTo.Console()
.CreateLogger();
- Start Logging: Once the sink is configured, you can log in using Serilog as usual. Log events will be sent to your Telegram channel.
For more detailed configuration options, please refer to the Configuration Wiki.
Examples
This repository includes several example projects that demonstrate how to use both libraries in various scenarios. These examples can be helpful if you're starting or looking to use a specific feature.
Contributing
Feel free to add any improvements you want via pull requests. All pull requests must be linked to an issue.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- X.Extensions.Logging.Telegram.Base (>= 2.0.0-beta)
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- X.Extensions.Logging.Telegram.Base (>= 2.0.0-beta)
-
net6.0
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- X.Extensions.Logging.Telegram.Base (>= 2.0.0-beta)
-
net8.0
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- X.Extensions.Logging.Telegram.Base (>= 2.0.0-beta)
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 |
---|---|---|
2.0.1-rc | 74 | 10/27/2024 |
2.0.0-beta | 88 | 8/30/2024 |
1.0.7 | 393 | 7/9/2024 |
1.0.6.1 | 2,967 | 3/5/2023 |
1.0.5.1 | 5,314 | 4/25/2022 |
1.0.4-preview | 198 | 12/20/2021 |
1.0.3 | 2,112 | 12/18/2021 |
1.0.2.1 | 456 | 11/5/2021 |
1.0.2 | 376 | 11/1/2021 |
1.0.1.5 | 720 | 6/27/2021 |
1.0.1.3 | 8,637 | 1/26/2021 |
1.0.1.2 | 340 | 1/26/2021 |