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); }
public static void Log(LogEntry logEntry) { if (logEntry == null) Log("Log entry cannot be null.", LoggingSeverity.Error); if (_IsLoggingEnabled) { try { lock (_LockObject) Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(logEntry); } catch (Exception exception) { string msg = String.Format(CultureInfo.CurrentCulture, "Logging failed for: {0}\r\nSeverity: {1}\r\nMessage: {2}", logEntry.CategoriesStrings, logEntry.Severity, logEntry.Message); WriteExceptionToEventLog(msg, exception); } } }
public void ConstructorWithExceptionPopulatesCategoriesProperty() { var exception = new InvalidOperationException() { Source = "FakeService" }; var entry = new LogEntry("fake message", exception, LoggingSeverity.Error); Assert.IsTrue(entry.Categories.Contains(exception.Source)); }
public void ConstructorPopulatesTimeStampProperty() { var entry = new LogEntry("fake message", new Collection<string>(), LoggingSeverity.Information); Assert.AreEqual(DateTime.Today.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture), entry.TimeStamp.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture)); }
public void ConstructorPopulatesSeverityPropertyAsWarning() { var entry = new LogEntry("fake message", new Collection<string>(), LoggingSeverity.Warning); Assert.AreEqual(TraceEventType.Warning, entry.Severity); }
public void ConstructorPopulatesSeverityPropertyAsDefault() { var entry = new LogEntry("fake message", new Collection<string>(), (LoggingSeverity)999); Assert.AreEqual(TraceEventType.Information, entry.Severity); }
public void ConstructorPopulatesMessageProperty() { LogEntry entry = new LogEntry("fake message", new Collection<string>(), LoggingSeverity.Information); Assert.AreEqual("fake message", entry.Message); }
public void ConstructorPopulatesCategoriesProperty() { var entry = new LogEntry("fake message", new Collection<string> { "CreditScoringService" }, LoggingSeverity.Information); Assert.IsTrue(entry.Categories.Contains("CreditScoringService")); }
public void SetLoggingSeveritySetsTheSeverity() { var entry = new LogEntry(); entry.SetLoggingSeverity(LoggingSeverity.Information); Assert.AreEqual(entry.Severity, TraceEventType.Information); }
public void ConstructorWithExceptionPopulatesTimeStampProperty() { var entry = new LogEntry("fake message", new InvalidOperationException(), LoggingSeverity.Error); Assert.AreEqual(DateTime.Today.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture), entry.TimeStamp.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture)); }
public void ConstructorWithExceptionPopulatesMessageProperty() { var entry = new LogEntry("fake message", new InvalidOperationException(), LoggingSeverity.Error); Assert.AreEqual("fake message\r\nException: System.InvalidOperationException: Operation is not valid due to the current state of the object.", entry.Message); }
/// <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); }
/// <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); }