Beispiel #1
0
        public bool WriteToLog(HappyTrip.Model.Entities.Log.LogMessage message)
        {
            bool isSuccessful = true;

            try
            {
                HttpContext httpContext = HttpContext.Current;

                string lf = httpContext.Server.MapPath("~/Log/") + logFile;

                StreamWriter sw = new StreamWriter(lf, true);

                StringBuilder sb = new StringBuilder();

                sb.Append("=====HappyTripLog: Start=======\n");
                sb.AppendFormat("Message: {0}\n", message.Message);
                sb.AppendFormat("Class Name: {0}\n", message.ClassName);
                sb.AppendFormat("Method Name: {0}\n", message.MethodName);
                sb.AppendFormat("Time of Log: {0}\n", message.MessageDateTime.ToLongTimeString() + ", " + message.MessageDateTime.ToLongDateString());
                sb.Append("=====HappyTripLog: End=======\n");

                string logMessage = sb.ToString();

                sw.WriteLine(logMessage);

                sw.Close();
                sw.Dispose();
            }
            catch (Exception)
            {
                isSuccessful = false;
            }
            return(isSuccessful);
        }
        public bool WriteToLog(HappyTrip.Model.Entities.Log.LogMessage message)
        {
            EventLog      evt          = new EventLog();
            StringBuilder sb           = new StringBuilder();
            bool          isSuccessful = true;

            try
            {
                sb.Append("=====HappyTripLog: Start=======\n");
                sb.AppendFormat("Message: {0}\n", message.Message);
                sb.AppendFormat("Class Name: {0}\n", message.ClassName);
                sb.AppendFormat("Method Name: {0}\n", message.MethodName);
                sb.AppendFormat("Time of Log: {0}\n", message.MessageDateTime.ToLongTimeString() + ", " + message.MessageDateTime.ToLongDateString());
                sb.Append("=====HappyTripLog: End=======\n");

                string logMessage = sb.ToString();

                evt.Source = "Application";
                evt.WriteEntry(logMessage, EventLogEntryType.Error);
            }
            catch (Exception)
            {
                isSuccessful = false;
            }

            return(isSuccessful);
        }
Beispiel #3
0
        public bool WriteToLog(HappyTrip.Model.Entities.Log.LogMessage message)
        {
            bool          isSuccessful = true;
            HttpContext   httpContext  = HttpContext.Current;
            StringBuilder sb           = new StringBuilder();

            try
            {
                sb.Append("\nDear Manager,\n\n");
                sb.Append("\n\n=====HappyTripLog: Start=======\n");
                sb.AppendFormat("Message: {0}\n", message.Message);
                sb.AppendFormat("Class Name: {0}\n", message.ClassName);
                sb.AppendFormat("Method Name: {0}\n", message.MethodName);
                sb.AppendFormat("Time of Log: {0}\n", message.MessageDateTime.ToLongTimeString() + ", " + message.MessageDateTime.ToLongDateString());
                sb.Append("=====HappyTripLog: End=======\n\n\n");
                sb.Append("PS: This is an auto generated mail. Please DO NOT REPLY to this mail\n");

                string logMessage = sb.ToString();


                string[] tokens      = mailParams.Split('#');
                string   fromAddress = tokens[0].Split(':')[1];
                string   toAddress   = tokens[1].Split(':')[1];
                string   smtpAddress = tokens[2].Split(':')[1];

                SmtpClient sc = new SmtpClient();
                if (smtpAddress.Equals("=dir"))
                {
                    sc.PickupDirectoryLocation = httpContext.Server.MapPath("~/LogMail/");
                    sc.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                }

                MailMessage mm = new MailMessage(fromAddress, toAddress);
                mm.Subject = "Email Log for HappyTrip";
                mm.Body    = logMessage;

                sc.Send(mm);
            }
            catch (Exception)
            {
                isSuccessful = false;
            }

            return(isSuccessful);
        }