Exemple #1
0
 /// <summary>
 /// public method get exception,handle it and save it to log file with json type
 /// </summary>
 public static void saveExceptionToLogFile(Exception ex)
 {
     try
     {
         string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Exceptions.json";
         using (StreamWriter writer = File.AppendText(filePath))
         {
             while (ex != null)
             {
                 BusinessObjects.Models.ApplicationException applicationException = new BusinessObjects.Models.ApplicationException();
                 applicationException.Date       = DateTime.Now;
                 applicationException.Type       = ex.GetType().FullName;
                 applicationException.Message    = ex.Message;
                 applicationException.StackTrace = ex.StackTrace;
                 var JException = JsonConvert.SerializeObject(applicationException);
                 writer.WriteLine(JException);
                 ex = ex.InnerException;
             }
         }
     }
     catch (Exception exception)
     {
         saveExceptionToLogFile(exception);
         throw exception;
     }
 }
Exemple #2
0
 /// <summary>
 /// public method get exception or event, handle it and save it to log file with json type
 /// </summary>
 public static void saveEventsAndExceptionsToLogFile(Exception ex, string message, EventLogEntryType type)
 {
     try
     {
         string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Exceptions.json";
         using (StreamWriter writer = File.AppendText(filePath))
         {
             if (ex == null)
             {
                 BusinessObjects.Models.logInfo loginfo = new BusinessObjects.Models.logInfo();
                 loginfo.Date    = DateTime.Now;
                 loginfo.Type    = type.ToString();
                 loginfo.Message = message;
                 var JException = JsonConvert.SerializeObject(loginfo);
                 writer.WriteLine(JException);
             }
             else
             {
                 while (ex != null)
                 {
                     BusinessObjects.Models.ApplicationException applicationException = new BusinessObjects.Models.ApplicationException();
                     applicationException.Date             = DateTime.Now;
                     applicationException.Type             = ex.GetType().FullName;
                     applicationException.Message          = ex.Message;
                     applicationException.StackTrace       = ex.StackTrace;
                     applicationException.DeveloperMessage = message;
                     var JException = JsonConvert.SerializeObject(applicationException);
                     writer.WriteLine(JException);
                     ex = ex.InnerException;
                 }
             }
         }
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }