Ejemplo n.º 1
0
 public TelegramLogger(
     string category,
     ITelegramBotClient botClient,
     TelegramLoggerOptions options,
     Func <string, LogLevel, bool> filter)
     : this(category, new TelegramLoggerSender(botClient, options.ChatId), options, filter)
 {
 }
Ejemplo n.º 2
0
        public static ILoggerFactory AddTelegramLogger(
            this ILoggerFactory loggerFactory,
            TelegramLoggerOptions options,
            Func <string, LogLevel, bool> filter = default)
        {
            var botClient = new TelegramBotClient(options.BotToken);

            loggerFactory?.AddProvider(new TelegramLoggerProvider(botClient, options, filter));
            return(loggerFactory);
        }
Ejemplo n.º 3
0
        public static ILoggerFactory AddTelegramLogger(
            this ILoggerFactory loggerFactory,
            Action <TelegramLoggerOptions> configure,
            Func <string, LogLevel, bool> filter = default)
        {
            var options = new TelegramLoggerOptions();

            configure(options);
            return(loggerFactory?.AddTelegramLogger(options, filter));
        }
Ejemplo n.º 4
0
 internal TelegramLogger(
     string category,
     TelegramLoggerSender messageQueue,
     TelegramLoggerOptions options,
     Func <string, LogLevel, bool> filter)
 {
     _category     = category ?? throw new ArgumentNullException(nameof(category));
     _messageQueue = messageQueue;
     _filter       = filter ?? ((cat, logLevel) => true);
     _options      = options;
 }
Ejemplo n.º 5
0
        public TelegramLoggerProvider(
            ITelegramBotClient botClient,
            TelegramLoggerOptions options,
            Func <string, LogLevel, bool> filter)
        {
            if (string.IsNullOrEmpty(options.ChatId) || string.IsNullOrWhiteSpace(options.ChatId))
            {
                throw new ArgumentException("Log receiver Id should not be null, empty or be a whitespace");
            }

            if (string.IsNullOrEmpty(options.SourceName) || string.IsNullOrWhiteSpace(options.SourceName))
            {
                throw new ArgumentException("Source name should not be null, empty or be a whitespace");
            }

            _filter       = filter;
            _options      = options;
            _messageQueue = new TelegramLoggerSender(botClient, options.ChatId);
        }