Skip to content

Commit 1ef2c9b

Browse files
authored
Merge pull request #29 from Bardin08/vbardin/update-configuration
Update defaults for batch emitting rules
2 parents f81cebc + 082823d commit 1ef2c9b

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

examples/ConsoleApp/Program.cs

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
using Serilog;
1+
using System.Collections.Immutable;
2+
using Serilog;
23
using Serilog.Events;
4+
using X.Serilog.Sinks.Telegram.Batch.Rules;
5+
using X.Serilog.Sinks.Telegram.Configuration;
36
using X.Serilog.Sinks.Telegram.Extensions;
7+
using X.Serilog.Sinks.Telegram.Filters.Fluent;
48

59
const string botToken = "TELEGRAM_BOT_TOKEN";
610
const string loggingChatId = "CHANNEL_OR_CHAT_ID";
711

8-
Log.Logger = new LoggerConfiguration()
9-
.WriteTo.TelegramCore(
10-
token: botToken,
11-
chatId: loggingChatId,
12-
logLevel: LogEventLevel.Verbose)
13-
.WriteTo.Console()
14-
.CreateLogger();
12+
ConfigAsMinimal(botToken, loggingChatId);
1513

1614
var logsCounter = 0;
1715
const int logsThreshold = 100;
@@ -22,4 +20,49 @@
2220
await Task.Delay(500);
2321

2422
logsCounter++;
23+
}
24+
25+
return;
26+
27+
void ConfigAsMinimal(string token, string tgChatId)
28+
{
29+
Log.Logger = new LoggerConfiguration()
30+
.WriteTo.TelegramCore(
31+
token: token,
32+
chatId: tgChatId,
33+
logLevel: LogEventLevel.Verbose)
34+
.CreateLogger();
35+
}
36+
37+
void ConfigAsExtended(string token, string tgChatId)
38+
{
39+
Log.Logger = new LoggerConfiguration()
40+
.WriteTo.Telegram(config =>
41+
{
42+
config.Token = token;
43+
config.ChatId = tgChatId;
44+
45+
config.Mode = LoggingMode.Logs;
46+
47+
config.BatchPostingLimit = TelegramSinkDefaults.BatchPostingLimit;
48+
config.BatchEmittingRulesConfiguration = new BatchEmittingRulesConfiguration();
49+
config.FormatterConfiguration = new FormatterConfiguration
50+
{
51+
UseEmoji = true,
52+
ReadableApplicationName = "MyTestApp",
53+
IncludeException = true,
54+
IncludeProperties = true,
55+
TimeZone = TimeZoneInfo.Utc
56+
};
57+
config.LogFiltersConfiguration = new LogsFiltersConfiguration
58+
{
59+
ApplyLogFilters = true,
60+
QueryBuilder = LogQueryBuilder.Create()
61+
.Exception.NotNull()
62+
.And().Level.Equals(LogEventLevel.Fatal)
63+
.And().Message.Contains("Payment API failed")
64+
};
65+
}, null!, LogEventLevel.Debug)
66+
.WriteTo.Console()
67+
.CreateLogger();
2568
}

src/X.Serilog.Sinks.Telegram/Configuration/BatchEmittingRulesConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public TimeSpan RuleCheckPeriod
3333
/// <summary>
3434
/// Gets or initializes the batch processing rules to be applied.
3535
/// </summary>
36-
public IImmutableList<IRule> BatchProcessingRules { get; init; } = null!;
36+
public IImmutableList<IRule> BatchProcessingRules { get; init; } = [];
3737

3838
/// <summary>
3939
/// Gets the execution hooks that are extracted from the batch processing rules.

src/X.Serilog.Sinks.Telegram/Configuration/TelegramSinkConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public int BatchPostingLimit
9090
/// <summary>
9191
/// Gets or sets the configuration for rules on emitting batches.
9292
/// </summary>
93-
public BatchEmittingRulesConfiguration BatchEmittingRulesConfiguration { get; set; } = null!;
93+
public BatchEmittingRulesConfiguration BatchEmittingRulesConfiguration { get; set; } = new();
9494

9595
/// <summary>
9696
/// Gets or sets the configuration for filtering logs.

0 commit comments

Comments
 (0)