Skip to content
Vladyslav Bardin edited this page Mar 11, 2024 · 7 revisions

X.Serilog.Sinks.Telegram Documentation

Introduction

The X.Serilog.Sinks.Telegram is a custom sink for Serilog, enabling 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 monitor application logs in real-time using your Telegram account conveniently.

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 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. Detailed feature documentation in the Log Filtering Wiki.

  • 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:

  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: 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: token,
        chatId: tgChatId,
        logLevel: LogEventLevel.Verbose)
    .CreateLogger();
  1. 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 look at the Configuration Wiki.

Example

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

❗️Error [YourApp] [2024-02-17 14:40:00 UTC]

Message: Message, "c5d700add5ec4384806a07027a3a4290"

Properties: 
Param_1: "c5d700add5ec4384806a07027a3a4290"

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!