/// <summary> /// Constructs the logger using the given configuration. /// </summary> /// <param name="configuration">Configuration to use</param> public L(LConfiguration configuration) { _configuration = configuration; if (string.IsNullOrEmpty(_configuration.Directory)) { _configuration.Directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"); } _openStreams = new OpenStreams(_configuration.Directory); if (_configuration.DeleteOldFiles.HasValue) { var min = TimeSpan.FromSeconds(5); var max = TimeSpan.FromHours(8); var cleanUpTime = new TimeSpan(_configuration.DeleteOldFiles.Value.Ticks / 5); if (cleanUpTime < min) { cleanUpTime = min; } if (cleanUpTime > max) { cleanUpTime = max; } _cleaner = new FolderCleaner( _configuration.Directory, _openStreams, _configuration.DeleteOldFiles.Value, cleanUpTime); } if (string.IsNullOrEmpty(_configuration.DateTimeFormat)) { _configuration.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; } _configuration.EnabledLabels = (_configuration.EnabledLabels ?? new string[0]).Select(l => _sanitizeLabel(l)).ToArray(); _lock = new object(); _longestLabel = 5; _disposed = false; }
/// <summary> /// Initializes the static instance using the given configuration. /// </summary> /// <param name="configuration">Configuration to use</param> public static void InitializeStatic(LConfiguration configuration) { lock (_staticLock) { if (_static != null && !_static._disposed) { throw new InvalidOperationException("The static instance is already initialized."); } _static = new L(configuration); // http://stackoverflow.com/q/16673332 if (AppDomain.CurrentDomain.IsDefaultAppDomain()) { AppDomain.CurrentDomain.ProcessExit += (sender, e) => _static.Dispose(); } else { AppDomain.CurrentDomain.DomainUnload += (sender, e) => _static.Dispose(); } } }