Giter Site home page Giter Site logo

jorik041 / x.extensions.logging.telegram Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ernado-x/x.extensions.logging.telegram

0.0 0.0 0.0 41 KB

Telegram logging provider

Home Page: https://www.nuget.org/packages/X.Extensions.Logging.Telegram

License: MIT License

C# 100.00%

x.extensions.logging.telegram's Introduction

NuGet Version

X.Extensions.Logging.Telegram

Telegram logging provider

What is Telegram?

What is Telegram? What do I do here? Telegram is a messaging app with a focus on speed and security, it’s super-fast, simple and free. You can use Telegram on all your devices at the same time β€” your messages sync seamlessly across any number of your phones, tablets or computers. Telegram has over 500 million monthly active users and is one of the 10 most downloaded apps in the world.

Why you need write logs to Telegram?

Because it very comfortable - you can receive important messages directly to your smartphone or laptop.

Prepare Telegram bot

For sending log messages into telegram channel or chat you need create telegram bot before. Here you can find how to do it. After you created bot add it to channel with admin role and allow bot to post messages.

Prepare Telegram channel

In telegram there are two types of channels: public and private. For public channel you can use channel name as ChatId in configuration.

For private channel you can use @JsonDumpBot to get private channel id. Just forward any message from private channelto this bot. Additional information you can find here.

Configure Telegram Logging provider

You can configure Telegram logging provider by code or by config file:

Code

var options = new TelegramLoggerOptions
{
    AccessToken = "1234567890:AAAaaAAaa_AaAAaa-AAaAAAaAAaAaAaAAAA",
    ChatId = "-0000000000000",
    LogLevel = LogLevel.Information,
    Source = "Human Readable Project Name"
};

...


builder
  .ClearProviders()
  .AddTelegram(options)
  .AddConsole();
                        

appconfig.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },
    "Telegram": {
      "LogLevel": "Warning",
      "AccessToken": "1234567890:AAAaaAAaa_AaAAaa-AAaAAAaAAaAaAaAAAA",
      "ChatId": "1234567890",
      "Source": "Human Readable Project Name"
    }
  },
  "AllowedHosts": "*"
}

and pass IConfiguration object to extensions method

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureLogging((context, builder) =>
        {
            if (context.Configuration != null)
                builder
                    .AddTelegram(context.Configuration)
                    .AddConsole();
        })
        .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });

x.extensions.logging.telegram's People

Contributors

ernado-x avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.