public void SetLoggingSeveritySetsTheSeverity() { var entry = new LogEntry(); entry.SetLoggingSeverity(LoggingSeverity.Information); Assert.AreEqual(entry.Severity, TraceEventType.Information); }
/// <summary> /// Logs a message and exception to a severity level. /// </summary> /// <param name="message">Message to be logged</param> /// <param name="loggingSeverity">Severity level of message</param> /// <param name="loggedException">Exception to be logged</param> public static void Log(string message, LoggingSeverity loggingSeverity, Exception loggedException) { if (string.IsNullOrWhiteSpace(message)) Log("Log message cannot be null, empty or have whitespace.", LoggingSeverity.Error); if (loggedException == null) Log("Log exception cannot be null.", LoggingSeverity.Error); LogEntry logEntry = new LogEntry(); string exceptionMessage = String.Format(CultureInfo.CurrentCulture, "{0}\r\nException: {1}", message, loggedException); logEntry.Message = exceptionMessage; logEntry.SetLoggingSeverity(loggingSeverity); Log(logEntry); }
public static void Log(LogEntry logEntry, Exception loggedException) { if (logEntry == null) Log("Log entry cannot be null.", LoggingSeverity.Error); if (loggedException == null) Log("Log exception cannot be null.", LoggingSeverity.Error); string exceptionMessage = String.Format(CultureInfo.CurrentCulture, "{0}\r\nException: {1}", logEntry.Message, loggedException); logEntry.Message = exceptionMessage; logEntry.SetLoggingSeverity(LoggingSeverity.Error); Log(logEntry); }
/// <summary> /// Logs a message and exception to a severity level. /// </summary> /// <param name="message">Message to be logged</param> /// <param name="loggingSeverity">Severity level of message</param> public static void Log(string message, LoggingSeverity loggingSeverity) { if (string.IsNullOrWhiteSpace(message)) Log("Log message cannot be null, empty or have whitespace.", LoggingSeverity.Error); LogEntry logEntry = new LogEntry(); logEntry.Message = message; logEntry.SetLoggingSeverity(loggingSeverity); Log(logEntry); }