/// <summary> /// Initialize the Web Service Event Log. /// </summary> static EventLog() { // Read the settings for the log from the configuration file. string logName = Properties.Settings.Default.EventLog; string sourceName = Properties.Settings.Default.EventLogSource; EventLog.isMultiuser = Properties.Settings.Default.IsMultiuserLog; // Try to get the log level from the app config, but if we can't for whatever reason (likely because it's out of range), use the default. try { EventLog.logLevel = (ErrorLogLevel)Properties.Settings.Default.LogLevel; } catch { EventLog.logLevel = ErrorLogLevel.Default; } // If the configuration file doesn't contain specifications for the log, then use the application log with // an undefined source. if (logName == null) { logName = "Application"; } if (sourceName == null) { sourceName = Process.GetCurrentProcess().MainModule.ModuleName; } // Initialize the Event Log. EventLog.eventLog = new System.Diagnostics.EventLog(); EventLog.eventLog.Log = logName; EventLog.eventLog.Source = sourceName; }
/// <summary> /// Logs to Console when at-level, and all messages to error log /// </summary> public static void Console(uint level, ErrorLogLevel errorLogLevel, string format, params object[] items) { var str = string.Format(format, items); LogError(errorLogLevel, str); if (Level >= level) { Console(level, str); } }
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel, string format, params object[] items) { var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items)); LogError(errorLogLevel, str); if (Level >= level) { Console(level, str); } }
/// <summary> /// Prints to log and error log /// </summary> /// <param name="errorLogLevel"></param> /// <param name="str"></param> public static void LogError(ErrorLogLevel errorLogLevel, string str) { string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str); switch (errorLogLevel) { case ErrorLogLevel.Error: ErrorLog.Error(msg); break; case ErrorLogLevel.Warning: ErrorLog.Warn(msg); break; case ErrorLogLevel.Notice: ErrorLog.Notice(msg); break; } }
/// <summary> /// is the loging enabled for a level /// </summary> /// <param name="isLogingOnFor"></param> /// <returns>true if logging enabled</returns> public static Boolean IsLoggingEnabledFor(ErrorLogLevel isLogingOnFor) { return((EventLog.logLevel & isLogingOnFor) == isLogingOnFor); }