示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventLogReader"/> class.
 /// </summary>
 /// <param name="eventLogConfig">Configuration.</param>
 /// <param name="logItemSerializerFactory">Optional serializer factory; DEFAULT will be base version.</param>
 public EventLogReader(
     EventLogConfig eventLogConfig,
     ISerializerFactory logItemSerializerFactory = null)
     : base(eventLogConfig, logItemSerializerFactory)
 {
     this.eventLogConfig = eventLogConfig ?? throw new ArgumentNullException(nameof(eventLogConfig));
 }
    /// <summary>
    /// Adds the telegram bot 4 event log using the specified logger for Serilog
    /// </summary>
    /// <param name="logger">The logger</param>
    /// <param name="config">The event log logger</param>
    /// <returns>The logger</returns>
    private static LoggerConfiguration AddTelegramBot4EventLog(
        this LoggerConfiguration logger,
        EventLogConfig config
        )
    {
        var tgBotConfig = config.TgBotConfig;
        var botToken    = config.BotToken;
        var channelId   = config.ChannelId;

        botToken ??= tgBotConfig.ApiToken;

        logger.WriteTo.Telegram(
            botToken: botToken,
            chatId: channelId.ToString(),
            applicationName: config.AppName,
            restrictedToMinimumLevel: LogEventLevel.Error
            );

        // logger.WriteTo.TelegramBot(
        //     token: botToken,
        //     chatId: channelId.ToString(),
        //     restrictedToMinimumLevel: LogEventLevel.Error,
        //     parseMode: ParseMode.HTML
        // );

        return(logger);
    }
        /// <summary>
        /// Builds a new <see cref="EventLog" /> object from <see cref="EventLogConfig" />.
        /// </summary>
        /// <param name="eventLogConfig">Configuration to use.</param>
        /// <returns>Event log object.</returns>
        public static EventLog NewEventLogObject(
            this EventLogConfig eventLogConfig)
        {
            if (eventLogConfig == null)
            {
                throw new ArgumentNullException(nameof(eventLogConfig));
            }

            return(new EventLog(eventLogConfig.LogName, eventLogConfig.MachineName, eventLogConfig.Source));
        }
示例#4
0
        public static void EventLog_custom_config___Test___Reading()
        {
            // Arrange
            var config = new EventLogConfig(new Dictionary <LogItemKind, IReadOnlyCollection <string> >(), "MySource", "MyLog", "Laptop", true);
            var logger = new EventLogReader(config);

            // Act
            var entries = logger.ReadAll();

            // Assert
            entries.Count.Should().NotBe(0);
        }
示例#5
0
        public static void EventLog_custom_config___Test___Logging_context_error()
        {
            // Arrange
            var config = new EventLogConfig(new Dictionary <LogItemKind, IReadOnlyCollection <string> >(), "MySource", "MyLog", "Laptop", true);
            var logger = new EventLogWriter(config);

            // Act
            logger.Log("Subject".ToLogEntry("Comment").ToLogItem(LogItemOrigin.ItsLogInternalErrors));

            // Assert
            /* Confirm entry - by hand */
        }
示例#6
0
        public static void EventLog_custom_config___Test___Non_logging_context()
        {
            // Arrange
            var config = new EventLogConfig(new Dictionary <LogItemKind, IReadOnlyCollection <string> >(), "MySourceLawson", "MyLogLawson", "MyMachine", true);
            var logger = new EventLogWriter(config);

            // Act
            logger.Log("Subject".ToLogEntry("Comment").ToLogItem(LogItemOrigin.ItsLogEntryPosted));

            // Assert
            /* Confirm no entry - by hand */
        }
示例#7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventLogWriter"/> class.
        /// </summary>
        /// <param name="eventLogConfig">Configuration.</param>
        /// <param name="logItemSerializerFactory">Optional serializer factory; DEFAULT will be base version.</param>
        public EventLogWriter(
            EventLogConfig eventLogConfig,
            ISerializerFactory logItemSerializerFactory = null)
            : base(eventLogConfig, logItemSerializerFactory)
        {
            this.eventLogConfig = eventLogConfig ?? throw new ArgumentNullException(nameof(eventLogConfig));

            if (this.eventLogConfig.ShouldCreateSourceIfMissing)
            {
                this.eventLogConfig.CreateEventLogSourceIfMissing();
            }
        }
示例#8
0
 public EventLogService(
     IOptionsSnapshot <EventLogConfig> eventLogConfig,
     ITelegramBotClient botClient,
     ChatService chatService,
     SettingsService settingsService
     )
 {
     _eventLogConfig  = eventLogConfig.Value;
     _botClient       = botClient;
     _chatService     = chatService;
     _settingsService = settingsService;
 }
示例#9
0
        public static void EventLogConfigurationConstructor___Valid___Works()
        {
            // Arrange && Act
            var actual = new EventLogConfig(new Dictionary <LogItemKind, IReadOnlyCollection <string> >());

            // Assert
            actual.Should().NotBeNull();
            actual.LogName.Should().Be(EventLogConfig.DefaultLogName);
            actual.MachineName.Should().Be(EventLogConfig.DefaultMachineName);
            actual.Source.Should().Be(Process.GetCurrentProcess().ProcessName);
            actual.ShouldCreateSourceIfMissing.Should().Be(false);
        }
示例#10
0
 /// <summary>
 /// Storage service constructor
 /// </summary>
 /// <param name="optionsCommonConfig"></param>
 /// <param name="optionsEventLogConfig"></param>
 /// <param name="hangfireConfig"></param>
 /// <param name="botClient"></param>
 /// <param name="queryService"></param>
 public StorageService(
     IOptionsSnapshot <CommonConfig> optionsCommonConfig,
     IOptionsSnapshot <EventLogConfig> optionsEventLogConfig,
     IOptionsSnapshot <HangfireConfig> hangfireConfig,
     ITelegramBotClient botClient,
     QueryService queryService
     )
 {
     _commonConfig   = optionsCommonConfig.Value;
     _eventLogConfig = optionsEventLogConfig.Value;
     _hangfireConfig = hangfireConfig.Value;
     _botClient      = botClient;
     _queryService   = queryService;
 }
示例#11
0
        public void Debug()
        {
            var config = new EventLogConfig(
                new Dictionary <LogItemKind, IReadOnlyCollection <string> >
            {
                { LogItemKind.String, null }, { LogItemKind.Object, null }, { LogItemKind.Exception, null },
                { LogItemKind.Unknown, null }, { LogItemKind.Telemetry, null },
            },
                shouldCreateSourceIfMissing: true,
                logName: "NaosLoggingTestLogName",
                source: "NaosLoggingTestSource");
            var json = new ObcJsonSerializer().SerializeToString(config);

            this.testOutputHelper.WriteLine(json);
        }
示例#12
0
 public BotService(
     ILogger <BotService> logger,
     IOptionsSnapshot <ButtonConfig> buttonConfig,
     IOptionsSnapshot <CommandConfig> commandConfig,
     IOptionsSnapshot <EventLogConfig> eventLogConfig,
     ITelegramBotClient botClient,
     CacheService cacheService
     )
 {
     _logger         = logger;
     _eventLogConfig = eventLogConfig.Value;
     _commandConfig  = commandConfig.Value;
     _buttonConfig   = buttonConfig.Value;
     _botClient      = botClient;
     _cacheService   = cacheService;
 }
示例#13
0
 public DatabaseService(
     ILogger <DatabaseService> logger,
     IOptionsSnapshot <EventLogConfig> eventLogConfig,
     IOptions <ConnectionStrings> connectionStrings,
     ITelegramBotClient botClient,
     BotService botService,
     QueryService queryService
     )
 {
     _logger            = logger;
     _eventLogConfig    = eventLogConfig.Value;
     _botClient         = botClient;
     _botService        = botService;
     _connectionStrings = connectionStrings.Value;
     _queryService      = queryService;
 }
        /// <summary>
        /// Create the <see cref="EventLog" /> <see cref="EventLog.Source" /> from configuration if it does not exist (requires considerable set of permissions).
        /// </summary>
        /// <param name="eventLogConfig">Configuration to use for creating source.</param>
        public static void CreateEventLogSourceIfMissing(
            this EventLogConfig eventLogConfig)
        {
            if (eventLogConfig == null)
            {
                throw new ArgumentNullException(nameof(eventLogConfig));
            }

            if (!eventLogConfig.ShouldCreateSourceIfMissing)
            {
                throw new ArgumentException(Invariant($"{nameof(eventLogConfig)}.{nameof(EventLogConfig.ShouldCreateSourceIfMissing)} == false"));
            }

            if (!EventLog.SourceExists(eventLogConfig.Source))
            {
                var sourceData = new EventSourceCreationData(eventLogConfig.Source, eventLogConfig.LogName);
                EventLog.CreateEventSource(sourceData);
            }
        }
示例#15
0
        public static void EventLogConfigurationConstructor___Valid_override_defaults___Works()
        {
            // Arrange
            var contextsToLog      = new Dictionary <LogItemKind, IReadOnlyCollection <string> >();
            var logName            = A.Dummy <string>();
            var machineName        = A.Dummy <string>();
            var source             = A.Dummy <string>();
            var shouldCreateSource = true;

            // Act
            var actual = new EventLogConfig(contextsToLog, source, logName, machineName, shouldCreateSource);

            // Assert
            actual.Should().NotBeNull();
            actual.LogName.Should().Be(logName);
            actual.MachineName.Should().Be(machineName);
            actual.Source.Should().Be(source);
            actual.ShouldCreateSourceIfMissing.Should().Be(shouldCreateSource);
        }
示例#16
0
 public JobsService(
     ILogger <JobsService> logger,
     IOptionsSnapshot <EventLogConfig> eventLogConfig,
     IOptions <RestrictionConfig> restrictionConfig,
     IBackgroundJobClient backgroundJobClient,
     IRecurringJobManager recurringJobManager,
     StepHistoriesService stepHistoriesService,
     ChatService chatService,
     ITelegramBotClient botClient,
     SettingsService settingsService
     )
 {
     _eventLogConfig       = eventLogConfig.Value;
     _restrictionConfig    = restrictionConfig.Value;
     _logger               = logger;
     _backgroundJobClient  = backgroundJobClient;
     _recurringJobManager  = recurringJobManager;
     _stepHistoriesService = stepHistoriesService;
     _chatService          = chatService;
     _botClient            = botClient;
     _settingsService      = settingsService;
 }
 public static IBinarySerializeAndDeserialize GetEventLogRawDataLogItemSerializer(
     this EventLogConfig eventLogConfig)
 {
     return(EventLogItemSerializer);
 }