All Projects → ernado-x → X.Extensions.Logging.Telegram

ernado-x / X.Extensions.Logging.Telegram

Licence: MIT license
Telegram logging provider

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to X.Extensions.Logging.Telegram

Formhelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
Stars: ✭ 155 (+384.38%)
Mutual labels:  aspnetcore, netcore
React Core Boilerplate
Powerful ASP.NET Core 3 templates with React, true server-side rendering and Docker support
Stars: ✭ 169 (+428.13%)
Mutual labels:  aspnetcore, aspnet
Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
Stars: ✭ 162 (+406.25%)
Mutual labels:  aspnetcore, netcore
Aspnetcore Angular Universal
ASP.NET Core & Angular Universal advanced starter - PWA w/ server-side rendering for SEO, Bootstrap, i18n internationalization, TypeScript, unit testing, WebAPI REST setup, SignalR, Swagger docs, and more! By @TrilonIO
Stars: ✭ 1,455 (+4446.88%)
Mutual labels:  aspnetcore, aspnet
Aspnetcore Vueclimiddleware
Helpers for building single-page applications on ASP.NET MVC Core using Vue Cli or Quasar Cli.
Stars: ✭ 253 (+690.63%)
Mutual labels:  aspnetcore, aspnet
Neventlite
NEventLite - An extensible lightweight library for .NET that manages the Aggregate lifecycle in an Event Sourced system. Supports Event and Snapshot storage providers like EventStore/Redis or SQL Server. Built with dependency injection in mind and seamlessly integrates with AspNetCore.
Stars: ✭ 117 (+265.63%)
Mutual labels:  aspnetcore, netcore
Aspnet Api Versioning
Provides a set of libraries which add service API versioning to ASP.NET Web API, OData with ASP.NET Web API, and ASP.NET Core.
Stars: ✭ 2,154 (+6631.25%)
Mutual labels:  aspnetcore, aspnet
Module Shop Mini Program
一个基于 .NET Core构建的简单、跨平台、模块化的商城系统
Stars: ✭ 89 (+178.13%)
Mutual labels:  aspnetcore, netcore
Blazortable
Blazor Table Component with Sorting, Paging and Filtering
Stars: ✭ 249 (+678.13%)
Mutual labels:  aspnetcore, aspnet
Identity.dapper
Identity package that uses Dapper instead EntityFramework for use with .NET Core
Stars: ✭ 234 (+631.25%)
Mutual labels:  aspnetcore, aspnet
Simple aspnet auth
Simple ASP.NET Authorisation boilerplate project. No EF, no database, no IdentityServer4 just a basic logging in system for both cookies and JWT and a controller with a set of examples.
Stars: ✭ 105 (+228.13%)
Mutual labels:  aspnetcore, aspnet
XAF Security E4908
This repository contains examples for Role-based Access Control, Permission Management, and OData / Web / REST API Services for Entity Framework and XPO ORM
Stars: ✭ 47 (+46.88%)
Mutual labels:  aspnetcore, netcore
Aspnetboilerplate
ASP.NET Boilerplate - Web Application Framework
Stars: ✭ 10,061 (+31340.63%)
Mutual labels:  aspnetcore, aspnet
Elmahcore
ELMAH for Net.Standard and Net.Core
Stars: ✭ 127 (+296.88%)
Mutual labels:  aspnetcore, netcore
Gitserver
ASP.NET Core Git HTTP Server
Stars: ✭ 98 (+206.25%)
Mutual labels:  aspnetcore, netcore
Netcorecms
NetCoreCMS is a modular theme supported Content Management System developed using ASP.Net Core 2.0 MVC. Which is also usable as web application framework. This project is still under development. Please do not use before it's first release.
Stars: ✭ 165 (+415.63%)
Mutual labels:  aspnetcore, netcore
Aspnetcore Vue Starter
*NEW* Asp.net Core & Vue.js (ES6) SPA Starter kit - Vuex, webpack, Web API, Docker, and more! By @TrilonIO
Stars: ✭ 1,182 (+3593.75%)
Mutual labels:  aspnetcore, aspnet
Aspnetcore.docs
Documentation for ASP.NET Core
Stars: ✭ 9,940 (+30962.5%)
Mutual labels:  aspnetcore, aspnet
Aspnetcore.identity.mongodb
MongoDB Data Store Adaptor for ASP.NET Core Identity
Stars: ✭ 210 (+556.25%)
Mutual labels:  aspnetcore, aspnet
SharpPlugs
.Net Core 鋒利扩展
Stars: ✭ 26 (-18.75%)
Mutual labels:  aspnetcore, netcore

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.

Do not forgot to add your bot as admin with write messages permission to channel.

Configure Telegram Logging provider

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

Code

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

...

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

appconfig.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    },
    "Telegram": {
      "LogLevel": {
        "Default": "Error",
        "WebApp.Controllers": "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>(); });

Use custom log writer

Now developers can use their own implementation for writing data to Telegram. Custom writer should implement ILogWriter interface:

var customLogWriter = new CustomLogWriter();
logBuilder.AddTelegram(options, customLogWriter);

Use custom message formatter

For implement custom message formatting ITelegramMessageFormatter can be used now.

private ITelegramMessageFormatter CreateFormatter(string name)
{
    return new CustomTelegramMessageFormatter(name);
}

logBuilder.AddTelegram(options, CreateFormatter);

For using custom message formatter delegate Func<string, ITelegramMessageFormatter> should be passed to extensions method AddTelegram. Delegate should be used because formatter needs to know which category is used for rendering the message.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].