using System; using System.Collections.Generic; using System.Web; using Elmah; namespace Sony.Filtr.ErrorLogging { public class ErrorLoggingManager { private static readonly ErrorLoggingManager _instance = new ErrorLoggingManager(); public static ErrorLoggingManager Instance { get { return _instance; } } public string CurrentApplicationName { get; set; } public void LogError(Exception ex) { try { if (HttpContext.Current != null) { ErrorSignal.FromCurrentContext().Raise(ex); } else { var dic = new Dictionary() { { "connectionStringName", "dbErrorLogging" }, { "applicationName", CurrentApplicationName ?? "Application" } }; ErrorLog errorLog = new MySqlErrorLog(dic); errorLog.Log(new Error(ex)); } } catch (Exception) { //We don't want logging to cause further errors... } } public void LogError(string errorMessage) { var exception = new Exception(errorMessage); this.LogError(exception); } public void LogError(Exception ex, string errorMessage) { this.LogError($"{errorMessage}{Environment.NewLine}ExceptionMessage: {ex.Message} ExceptionStack: {ex.StackTrace}"); } } }