예제 #1
0
        public bool ModifyNlogConfigDefinition(int identity, string modifiedBy,
                                               bool deleteOldLogs, int deleteOldLogDays, int hoursToNewLogFile, bool activated,
                                               bool dontChangeModifiedBy)
        {
            _logger.Info($"Method for NLog configuration modification fired. Identity = {identity}, change only acivitiness = {dontChangeModifiedBy}.");

            try
            {
                NLogConfigurationDefinition definition = _realm.All <NLogConfigurationDefinition>().Single(x => x.Identity == identity);

                using (var trans = _realm.BeginWrite())
                {
                    if (!dontChangeModifiedBy)
                    {
                        definition.ModifiedBy = modifiedBy;
                    }
                    definition.OldLogDeletion          = deleteOldLogs;
                    definition.OldLogDeletionDays      = deleteOldLogDays;
                    definition.HoursToCreateNewLogFile = hoursToNewLogFile;
                    definition.ConfigActivated         = activated;
                    trans.Commit();
                }

                _logger.Info("Changing NLog configuration successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to modify existing Nlog config definition: {ex.Message}.");
                return(false);
            }
        }
예제 #2
0
        //change NLog config in runtime
        public static void ChangeCurrentNLogConfig()
        {
            _logger.Info($"Changing current NLog configuration procedure started.");

            NLogConfigurationDefinition nlogCurrentConfig = GetCurrentNLogCOnfig();

            NLogConfigurator.ChangeNLogConfiguration(nlogCurrentConfig.OldLogDeletion, nlogCurrentConfig.OldLogDeletionDays,
                                                     nlogCurrentConfig.HoursToCreateNewLogFile);
        }
예제 #3
0
        //assigning current NLog config at the application startup
        private static void ConfigNLogForFirstTime()
        {
            _logger.Info($"Configuring NLog at application startup started.");

            NLogConfigurationDefinition nlogCurrentConfig = GetCurrentNLogCOnfig();

            NLogConfigurator.NLogConfiguration(nlogCurrentConfig.OldLogDeletion, nlogCurrentConfig.OldLogDeletionDays,
                                               nlogCurrentConfig.HoursToCreateNewLogFile);
        }
예제 #4
0
        //checking what data changed
        private (bool, bool) CheckIfConfigChanged(NlogConfigModel item, NLogConfigurationDefinition originalItem)
        {
            bool modifiedData = false;
            bool modifiedOnlyActivityOfConfig = false;

            if (item.DeleteOldLogs != originalItem.OldLogDeletion || item.SelectedDays.Days != originalItem.OldLogDeletionDays ||
                item.SelectedHours.Hours != originalItem.HoursToCreateNewLogFile)
            {
                modifiedData = true;
            }
            if (item.ConfigActivated != originalItem.ConfigActivated)
            {
                modifiedOnlyActivityOfConfig = true;
            }

            return(modifiedData, modifiedOnlyActivityOfConfig);
        }
예제 #5
0
        public bool DeleteNLogConfig(int identity)
        {
            _logger.Info($"Method for deleting NLog configuration from DB fired. Identity = {identity}.");

            try
            {
                NLogConfigurationDefinition config = _realm.All <NLogConfigurationDefinition>().Single(x => x.Identity == identity);
                using (var trans = _realm.BeginWrite())
                {
                    _realm.Remove(config);
                    trans.Commit();
                }

                _logger.Info($"Deleting NLog configuration from DB successfull.");

                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error($"Error while trying to delete existing NLog config: {ex.Message}.");
                return(false);
            }
        }