Skip to content

Serilog.Sinks.Telegram is a library to save logging information from Serilog to Telegram. The assembly was written and tested in .Net 5.0.

License

Notifications You must be signed in to change notification settings

zoinkydoink/Serilog.Sinks.Telegram

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serilog.Sinks.Telegram

Serilog.Sinks.Telegram is a library to save logging information from Serilog to Telegram. The assembly was written and tested in .Net 5.0.

Build status GitHub issues GitHub forks GitHub stars License: MIT Nuget NuGet Downloads Known Vulnerabilities Gitter

Available for

  • NetFramework 4.6
  • NetFramework 4.6.2
  • NetFramework 4.7
  • NetFramework 4.7.2
  • NetFramework 4.8
  • NetStandard 2.0
  • NetStandard 2.1
  • NetCore 2.1
  • NetCore 3.1
  • Net 5.0

Net Core and Net Framework latest and LTS versions

Basic usage:

var logger = new LoggerConfiguration()
	.WriteTo.Telegram("botToken", "chatId")
    .CreateLogger();

The project can be found on nuget.

Configuration options:

Parameter Meaning Example Default value
botToken The Telegram bot token. "123151488:AAgshf4r373rffsdfOfsdzgfwezfzqwfr7zewE" None, is mandatory.
chatId The Telegram chat id. "12345" None, is mandatory.
batchSizeLimit The maximum number of events to include in a single batch. batchSizeLimit: 40 30
period The time to wait between checking for event batches. period: new TimeSpan(0, 0, 20) 00:00:05
formatProvider The IFormatProvider to use. Supplies culture-specific formatting information. Check https://docs.microsoft.com/en-us/dotnet/api/system.iformatprovider?view=netframework-4.8. new CultureInfo("de-DE") null
restrictedToMinimumLevel The minimum level of the logging. restrictedToMinimumLevel: LogEventLevel.Verbose LogEventLevel.Verbose
sendBatchesAsSingleMessages A value indicating whether the batches are sent as single messages or as one block of messages. false true
includeStackTrace A value indicating whether the stack trace should be shown or not. false true
failureCallback Adds an option to add a failure callback action. failureCallback: e => Console.WriteLine($"Sink error: {e.Message}") null

Configuration via JSON options

{
    "Serilog": {
        "Using": [ "Serilog.Sinks.Telegram" ],
        "MinimumLevel": {
            "Default": "Warning"
        },
        "WriteTo": [
            {
                "Name": "Telegram",
                "Args": {
                    "botToken": "123151488:AAgshf4r373rffsdfOfsdzgfwezfzqwfr7zewE",
                    "chatId": "12345",
                    "restrictedToMinimumLevel": "Warning",
                    "applicationName": "My App",
                    "dateFormat": "yyyy-MM-dd  HH:mm:sszzz"
                }
            }
        ]
    }
}

Further information

This sink is basically the same as https://github.com/oxozle/serilog-sinks-telegram but is maintained and provides badging of events.

You need to get a bot API token following https://core.telegram.org/api#bot-api.

Change history

See the Changelog.

About

Serilog.Sinks.Telegram is a library to save logging information from Serilog to Telegram. The assembly was written and tested in .Net 5.0.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 98.8%
  • Batchfile 1.2%