Code Monkey home page Code Monkey logo

loggerbot's Introduction

LoggerBot NuGet Package

Overview

The LoggerBot NuGet package provides a logging service that integrates with Telegram bots. It allows developers to easily log messages of various types (error, info, warning, success, and generic messages) to a designated Telegram chat using a Telegram bot.

Installation

You can install the LoggerBot NuGet package via the NuGet Package Manager or the .NET CLI:

dotnet add package LoggerBot

Usage

  1. Configure LoggerBot First, configure LoggerBot in your application's startup code to register the logger service in the dependency injection container:
using LoggerBot;

builder.Services.AddLoggerBot();
  1. Inject and Use LoggerService Inject the ILoggerService interface into your classes where logging is required and use its methods to log messages:
using LoggerBot.Services;

public class MyClass
{
    private readonly ILoggerService _logger;

    public MyClass(ILoggerService logger)
    {
        _logger = logger;
    }

    public async Task SomeMethod()
    {
        // Log an error message
        await _logger.ErrorAsync("An error occurred.");

        // Log an info message
        await _logger.InfoAsync("Some information message.");

        // Log a success message
        await _logger.SuccessAsync("Operation completed successfully.");

        // Log a warning message
        await _logger.WarningAsync("Warning: Resource limit exceeded.");

        // Log a generic message
        await _logger.MessageAsync("A generic message.");
    }
}

Configuration

The LoggerBot requires configuration settings to connect to your Telegram bot. Ensure the following configuration keys are present in your appsettings.json or environment variables:

LoggerBot:Token: The token of your Telegram bot.

LoggerBot:ChatId: The ID of the Telegram chat where logs will be sent.

LoggerBot:TimeZone: The time zone identifier used to format log timestamps.

Example:

"LoggerBot": {
  "Token": "bot-token",
  "ChatId": "-100chatId",
  "TimeZone": "Asia/Tashkent"
}

Supported Log Types

  • Error: Used for logging error messages.

  • Info: Used for logging informational messages.

  • Success: Used for logging success messages.

  • Warning: Used for logging warning messages.

  • Message: Used for logging generic messages.

Feel free to expand upon this documentation with more details specific to your package's usage or additional features!

loggerbot's People

Contributors

nodirbek-abdulaxadov avatar

Watchers

 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.