public FileLogger(FileLoggerConfig config) { try { SetConfig(config); } catch (ArgumentException) { FileLoggerConfig conf = new FileLoggerConfig() { LogPath = config.LogPath, LogName = "notInitNameLog", LogLevel = config.LogLevel, }; SetConfig(conf); } }
/// <summary> /// Задать конфигурацию /// </summary> /// <param name="logConfig">Конфигурация</param> /// <exception cref="ArgumentException">Имя файла не определено</exception> public void SetConfig(FileLoggerConfig logConfig) { lock (_lockerObject) { if (string.IsNullOrWhiteSpace(logConfig.LogName)) { throw new ArgumentException("fileName"); } Config = logConfig; if (!Directory.Exists(Config.LogPath)) { Directory.CreateDirectory(Config.LogPath); } FullPathToLastWritedLogFile = Path.Combine(Config.LogPath, string.Format("{0} - {1}{2}", Config.LogName, DateTime.Now.ToShortDateString(), ".txt")); } FileOperations.CompressAllFiles(Directory.GetFiles(Config.LogPath, $"{Config.LogName} - *.txt")); }
public static void SetConfigurationFileLogger(FileLoggerConfig _config) { Logger.SetConfig(_config); }