1- using Serilog ;
1+ using System . Collections . Immutable ;
2+ using Serilog ;
23using Serilog . Events ;
4+ using X . Serilog . Sinks . Telegram . Batch . Rules ;
5+ using X . Serilog . Sinks . Telegram . Configuration ;
36using X . Serilog . Sinks . Telegram . Extensions ;
7+ using X . Serilog . Sinks . Telegram . Filters . Fluent ;
48
59const string botToken = "TELEGRAM_BOT_TOKEN" ;
610const 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
1614var logsCounter = 0 ;
1715const int logsThreshold = 100 ;
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