Skip to content

Commit 082823d

Browse files
committed
Update examples
Add extended(the old one) configuration method example
1 parent 1f6b174 commit 082823d

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
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
}

0 commit comments

Comments
 (0)