private static bool IsAllowed(LogLevel level) { var levelConfigured = StateManager.Settings["EventLogLevel"] as string; var config = Descriptor.Get<LogLevel>(levelConfigured) ?? LogLevel.Unspecified; return level.Order >= config.Order; }
/// <summary> /// Logs the specified message with the specified <see cref="LogLevel"/> and user information. /// </summary> /// <param name="level">The <see cref="LogLevel"/> to log.</param> /// <param name="user">The user information to log.</param> public static void Log(LogLevel level, string message, IUser user = null) { var currentUser = GetCurrentUser(); foreach (var logger in Loggers) { logger.Log(level, message, user ?? currentUser); } }
/// <summary> /// Logs the specified message with the specified loglevel and user information. /// </summary> /// <param name="message">The message to log.</param> /// <param name="level">The loglevel to log.</param> /// <param name="user">The user information to log.</param> public void Log(LogLevel level, string message, IUser user) { message = string.Format("{0} - ({1}).", message, Assembly.GetCallingAssembly().FullName); if (IsAllowed(level)) { if (level == LogLevel.Informational) appLog.WriteEntry(message, EventLogEntryType.Information); else if (level == LogLevel.Warning) appLog.WriteEntry(message, EventLogEntryType.Warning); else if (level == LogLevel.Error) appLog.WriteEntry(message, EventLogEntryType.Error); else appLog.WriteEntry(message, EventLogEntryType.Information); } }
/// <summary> /// Logs the specified message with the specified <see cref="LogLevel"/> and user information. /// </summary> /// <param name="level">The <see cref="LogLevel"/> to log.</param> /// <param name="message">The message to log.</param> /// <param name="user">The user information to log.</param> public void Log(LogLevel level, string message, IUser user = null) { Debug.WriteLine(level + ": " + message); }
/// <summary> /// Log the error message as per the specified log level. /// </summary> /// <param name="message">The error messages which will logged.</param> /// <param name="level">The Adf.Core.LogLevel that defines the comparison with configuration loglevel.</param> /// <param name="user">The Adf.Core.IDomainObject object - not in use.</param> public void Log(LogLevel level, string message, IUser user) { if (message == null) throw new ArgumentNullException("message"); if (IsAllowed(level)) { Log(message, user); } }