-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
In the context of the Telegram Sink for logging, several configuration classes and enums are available. These classes provide a way to configure the sink according to specific needs.
- TelegramSinkConfiguration
- LoggingMode
- BatchEmittingRulesConfiguration
- FormatterConfiguration
- LogsFiltersConfiguration
- LogQueryBuilder
- TelegramSinkDefaults
- Usage Examples
This is the primary configuration class which contains settings required for the operation of the Telegram Sink.
| Property | Type | Description |
|---|---|---|
| Token | string | Token for Telegram API access. |
| ChatId | string | Identifies the chat to which log messages will be posted. |
| BatchPostingLimit | int | The maximum number of events to post in a single batch. |
| Mode | LoggingMode | Sets the logging mode. |
| FormatterConfiguration | FormatterConfiguration | Configuration for formatting logs. |
| BatchEmittingRulesConfiguration | BatchEmittingRulesConfiguration | Configuration for rules on emitting batches. |
| LogFiltersConfiguration | LogsFiltersConfiguration | Configuration for filtering logs. |
An enumeration that allows choosing between two ways of logging.
A. Logs: Log messages will be published to the specified Telegram channel.
B. AggregatedNotifications: Messages will contain info about all notifications received during a batch period or batch limit.
Configuration class for managing batch-emitting rules.
| Property | Type | Description |
|---|---|---|
| RuleCheckPeriod | TimeSpan | Check period for batch emit rules. |
| BatchProcessingRules | IImmutableList | The batch processing rules to be applied. |
Settings for formatting log messages.
| Property | Type | Description |
|---|---|---|
| UseEmoji | bool | Indicates whether to use emojis in the output. |
| ReadableApplicationName | string | User-friendly name of the application. |
| IncludeException | bool | Indicates whether to include exception details in the output. |
| IncludeProperties | bool | Indicates whether to include property details in the output. |
| TimeZone | TimeZoneInfo? | Indicates which time zone to use in the output timestamp. If null, server time will be used. |
Configuration class for applying log filters.
| Property | Type | Description |
|---|---|---|
| ApplyLogFilters | bool | Indicates whether to apply log filters. |
| LogQueryBuilder | LogQueryBuilder | List of filters to be applied. |
Fluent API-based filter builder. This allows to configure log filtering based on the convenient API.
Contains the default configuration values for the Telegram Sink.
You can configure Telegram sink with 2 methods. For quickstart, you can use the TelegramCore method. Also, you can use the Telegram method for advanced configuration.
For a quickstart you can use the TelegramCore method
Log.Logger = new LoggerConfiguration()
.WriteTo.TelegramCore(
token: botToken,
chatId: loggingChatId,
logLevel: LogEventLevel.Verbose)
.WriteTo.Console()
.CreateLogger();Here is an example of how to configure the Telegram Sink using advanced configuration, an extension method on the LoggerConfiguration class:
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,
TimeZone = TimeZoneInfo.Utc
};
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();
logger.Information("This is a test log message");This code configures the TelegramSinkConfiguration instance through a delegate and an extension method. This provides a more fluent API and makes the configuration step more clear and straightforward. You would add further sinks and then create the logger from your loggerConfiguration.
In this example, new MyCustomMessageFormatter() is used for message formatting. You should replace
MyCustomMessageFormatter with your actual implementation of the IMessageFormatter or leave it null to use one of the
default one.
Also, add your own batch emitting rules and filters per your requirements.
Replace your_telegram_bot_token and your_chat_id with your Telegram bot token and chat ID.
Important: Always validate the configuration towards the end before using it to instantiate an object. This is to ensure that the provided settings are valid and appropriate for the operation of the Telegram sink.