/// <summary> /// Instantiates an new instance with the data from the <paramref name="configuration"/>. /// </summary> /// <param name="configuration">The configuration to use to populate the new instance.</param> public CachedLog(Configuration.IConfigurationGroup configuration) : this() { // check if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (configuration.Key != "Log") { throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"Log\". Configuration Key={configuration.Key}", nameof(configuration)); } // Log if (!configuration.ContainsKey("Log")) { throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"Log\".", nameof(configuration)); } InnerLog = (ILog)Core.Configuration.ConfigurationHelper.InstantiateTypeFromConfigurationGroup(null, configuration["Log"]); InnerLog.Open(); // AutoFlushLogs AutoFlushEnabled = (bool)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "AutoFlushLogs", typeof(bool)).Value; // FlushMaximumLogs FlushMaximumLogs = (int)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "FlushMaximumLogs", typeof(int)).Value; // FlushTimeLimit FlushTimeLimit = (TimeSpan)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "FlushTimeLimit", typeof(TimeSpan)).Value; }
/// <summary> /// Will delete the log. /// </summary> /// <remarks>This will permanently delete all log entries; this action <i>cannot</i> be undone.</remarks> public void Delete() { lock (InnerLog.SyncObject) { InnerLog.Delete(); _MessageCache.Clear(); } }
/// <summary> /// Returns each log entry in the log which returns <b>true</b> from the <paramref name="logEntryFilterPredicate"/>. /// </summary> /// <remarks>This will execute <see cref="FlushLogs"/> before opening the log.</remarks> /// <param name="logEntryFilterPredicate">A function which takes an <see cref="ILogEntry"/> and returns <b>true</b> to include the log entry, or <b>false></b> to skip the log entry.</param> /// <returns>Every log entry from the log which returns <b>true</b> from the <paramref name="logEntryFilterPredicate"/>.</returns> public IEnumerable <ILogEntry> Read(Func <ILogEntry, bool> logEntryFilterPredicate) { lock (InnerLog.SyncObject) { FlushLogs(); return(InnerLog.Read(logEntryFilterPredicate)); } }
/// <summary> /// Will create an empty log. /// </summary> public void Create() { lock (InnerLog.SyncObject) { InnerLog.Create(); _MessageCache.Clear(); } }
/// <summary> /// Closes the log. /// </summary> public void Close() { lock (InnerLog.SyncObject) { FlushLogs(); InnerLog.Close(); } }
/// <summary> /// Will remove all log entries from the log. /// </summary> /// <remarks> /// This will permanently delete all log entries; this action <i>cannot</i> be undone. /// <para>This only clears the log, it will <i>not</i> delete it.</para> /// </remarks> /// <returns>The number of log entires removed.</returns> public int Clear() { lock (InnerLog.SyncObject) { var count = InnerLog.LogCount + _MessageCache.Count; InnerLog.Clear(); _MessageCache.Clear(); return(count); } }
/// <summary> /// This will write all log entries in the cache to the hosted event log, clearing all cached log entries. /// </summary> public void FlushLogs() { lock (InnerLog.SyncObject) { if (_MessageCache.Count > 0) { if (_MessageCache.Count > LargestFlushCount) { LargestFlushCount = _MessageCache.Count; } InnerLog.Write(_MessageCache); LastFlushCount = _MessageCache.Count; _MessageCache.Clear(); _LastDateCacheFlushed = DateTime.Now; ++FlushGeneration; } } }
public static void FatalFormat(string format, params object[] args) { InnerLog.FatalFormat(format, args); }
public static void ErrorFormat(string format, params object[] args) { InnerLog.ErrorFormat(format, args); }
public static void WarnFormat(string format, params object[] args) { InnerLog.WarnFormat(format, args); }
public static void DebugFormat(string format, params object[] args) { InnerLog.DebugFormat(format, args); }
/// <summary> /// Opens, or creates, the log. /// </summary> public void Open() { InnerLog.Open(); }