/// <summary> /// Ajoute un texte dans le fichier log /// </summary> public static void AppendException(Exception ex) { try { //string source = "www.upsideo.fr";//Upsilab.Business.Utility.UrlHelper.GetHost(); //like "www.upsideo.fr" /*string source = Upsilab.Business.Utility.UrlHelper.GetHost2(); //like "www.upsideo.fr" if (!EventLog.SourceExists(source)) { EventLog.CreateEventSource(source, "Upsideo Log"); } EventLog myLog = new EventLog(); myLog.Source = source; string textToAdd = string.Format("{0} : {1}\r\n{2}\r\n{3}\r\n\r\n", DateTime.Now.ToString(), ex.Message, ex.InnerException, ex.StackTrace); myLog.WriteEntry(textToAdd); */ //New //Ajout dans la table ErrorLog using (Upsilab.Data.Model.UpsilabEntities db = new Data.Model.UpsilabEntities()) { var errorLog = new Upsilab.Data.Model.ErrorLog() { idUser = (SessionManager.GetUserSession() != null) ? SessionManager.GetUserSession().idUser : (Guid?)null, ExtranetType = ConfigurationManager.ExtranetType.ToString(), Message = string.Format("{0} : {1}\r\n{2}\r\n{3}\r\n\r\n", DateTime.Now.ToString(), ex.Message, ex.InnerException, ex.StackTrace), Host = Upsilab.Business.Utility.UrlHelper.GetHost2(), UserAgent = (HttpContext.Current != null) ? HttpContext.Current.Request.UserAgent : null, DateCreated = DateTime.Now }; db.AddToErrorLog(errorLog); db.SaveChanges(); } } catch { } }
public static void LogOnDB(string msg) { try { using (Upsilab.Data.Model.UpsilabEntities db = new Data.Model.UpsilabEntities()) { var errorLog = new Upsilab.Data.Model.ErrorLog() { idUser = (SessionManager.GetUserSession() != null) ? SessionManager.GetUserSession().idUser : (Guid?)null, ExtranetType = ConfigurationManager.ExtranetType.ToString(), Message = msg, Host = Upsilab.Business.Utility.UrlHelper.GetHost2(), UserAgent = (HttpContext.Current != null) ? HttpContext.Current.Request.UserAgent : null, DateCreated = DateTime.Now }; db.AddToErrorLog(errorLog); db.SaveChanges(); } } catch { } }