public LogRotater(RotateType supportedType, LogRotateOptions options) { if (options.RotateType != supportedType) { throw new NotSupportedException("only support " + supportedType + " but encounter " + options.RotateType); } this.options = options; }
private void BuildRotateType(LogRotateOptions options) { foreach (var name in Enum.GetNames(typeof(RotateType))) { string arguments; if (parameters.TryGetValue(name, out arguments)) { options.RotateType = (RotateType)Enum.Parse(typeof(RotateType), name); options.RotateArguments = arguments; } } }
public virtual LogRotateOptions Build() { var options = new LogRotateOptions(); BuildRotateType(options); BuildRotate(options); BuildCompress(options); BuildDelayCompress(options); BuildIncludeSubDirs(options); BuildRootFilter(options); return(options); }
public LogRotateOptions[] Reconfig() { var builders = new FileLogRotateOptionsBuilderProvider(optionsFile).CreateBuilders(); var rotaters = new LogRotater[builders.Length]; var options = new LogRotateOptions[builders.Length]; for (int i = 0; i < builders.Length; i++) { options[i] = builders[i].Build(); rotaters[i] = LogRotater.Create(options[i]); } this.rotaters = rotaters; return(options); }
private void BuildRootFilter(LogRotateOptions options) { options.Root = Path.GetDirectoryName(root); options.Filter = Path.GetFileName(root); if (string.IsNullOrEmpty(options.Root)) { options.Root = "logs"; } if (string.IsNullOrEmpty(options.Filter)) { options.Filter = "*.log"; } }
private void BuildCompress(LogRotateOptions options) { string compress; options.Compress = true; if (parameters.TryGetValue("compress", out compress)) { if (compress == "off") { options.Compress = false; } else if (!string.IsNullOrEmpty(compress) && compress != "on") { throw new InvalidOperationException("invalid compress value " + compress); } } }
private void BuildRotate(LogRotateOptions options) { string rotate; if (parameters.TryGetValue("rotate", out rotate)) { int days; if (!int.TryParse(rotate, out days)) { throw new InvalidOperationException("invalid rotate value " + rotate); } options.Rotate = days; } else { options.Rotate = 90; } }
private void BuildDelayCompress(LogRotateOptions options) { string delaycompress; int days = 1; if (parameters.TryGetValue("delaycompress", out delaycompress)) { if (!string.IsNullOrEmpty(delaycompress) && !int.TryParse(delaycompress, out days)) { throw new InvalidOperationException("invalid delaycompress value " + delaycompress); } if (days < 0) { throw new InvalidOperationException("delaycompress out of range 0."); } } options.DelayCompress = days; }
public static LogRotater Create(LogRotateOptions options) { if (options == null) { throw new ArgumentNullException("options"); } switch (options.RotateType) { case RotateType.Minutely: return(new MinutelyLogRotater(options)); case RotateType.Hourly: return(new HourlyLogRotater(options)); case RotateType.Daily: return(new DailyLogRotater(options)); case RotateType.Weekly: return(new WeeklyLogRotater(options)); case RotateType.Monthly: return(new MonthlyLogRotater(options)); case RotateType.Yearly: return(new YearlyLogRotater(options)); } throw new NotSupportedException(options.RotateType.ToString()); }
public MinutelyLogRotater(LogRotateOptions options) : base(RotateType.Minutely, options) { this.time = options.RotateArguments ?? "0"; }
private void BuildIncludeSubDirs(LogRotateOptions options) { options.IncludeSubDirs = parameters.ContainsKey("includesubdirs"); }
public YearlyLogRotater(LogRotateOptions options) : base(RotateType.Yearly, options) { this.time = options.RotateArguments ?? "1.1"; }
public MonthlyLogRotater(LogRotateOptions options) : base(RotateType.Monthly, options) { this.time = options.RotateArguments ?? "1"; }
public DailyLogRotater(LogRotateOptions options) : base(RotateType.Daily, options) { this.time = options.RotateArguments ?? "0:00:00"; }