Skip to content
Vladyslav Bardin edited this page Aug 11, 2023 · 7 revisions

X.Serilog.Sinks.Telegram Documentation

Introduction

The X.Serilog.Sinks.Telegram is a custom sink for Serilog that enables you to send log events to a Telegram channel. This sink utilizes the Telegram Bot API to post log messages as messages in a specified Telegram channel, allowing you to conveniently monitor application logs in real-time using your Telegram account.

Features Overview

  • 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 have the flexibility to 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 any 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:

  1. Install the Package: You can install the sink package from NuGet using the following command:
   dotnet add package X.Serilog.Sinks.Telegram
  1. Configure the Sink: In your application's configuration, set up the Telegram sink with the appropriate settings. Here's an example configuration in C#:
var logger = new LoggerConfiguration()
    .Telegram(config =>
    {
        config.Token = "your_telegram_bot_token";
        config.ChatId = "your_chat_id";
        config.BatchPostingLimit = 10;
        config.Mode = LoggingMode.Logs;
        config.FormatterConfiguration = new FormatterConfiguration
        {
            UseEmoji = true,
            ReadableApplicationName = "MyTestApp",
            IncludeException = true,
            IncludeProperties = true
        };
        config.BatchEmittingRulesConfiguration = new BatchEmittingRulesConfiguration
        {
            // Batch Emitting rules configuration here...
        };
        config.LogFiltersConfiguration = new LogsFiltersConfiguration
        {
            ApplyLogFilters = true,
            FiltersOperator = LogFiltersOperator.Or,
            Filters = new List<IFilter> {
                // Your filters here...
            }
        };
    }, null, LogEventLevel.Debug)
    .CreateLogger();
  1. Start Logging: Once the sink is configured, you can start logging using Serilog as you normally would. Log events will be sent to your Telegram channel.

For more detailed configuration options, please refer to the Configuration Wiki.

Example

Here's an example of how a log message might appear in your Telegram channel:

ℹ️ [8/9/2023 6:59:05 PM] WebApp Example

Message: Application started. Press Ctrl+C to shut down.
Properties: 
{
  "SourceContext": {
    "Value": "Microsoft.Hosting.Lifetime"
  }
}

License

This project is licensed under the MIT License.

For more information, troubleshooting, and detailed configuration instructions, please refer to the GitHub Repository.

Feel free to contribute to this project by opening issues or submitting pull requests!

Clone this wiki locally