Example #1
0
 /// <summary>
 /// Writes the warnings to the Log.
 /// </summary>
 /// <param name="userID"></param>
 /// <param name="severityID"></param>
 /// <param name="className"></param>
 /// <param name="functionName"></param>
 /// <param name="message"></param>
 /// <returns></returns>
 public override bool WriteToWarningLog(string userID, Severity severityID, string className, string functionName, string message)
 {
     try
     {
         if (CreateEventSource())
         {
             if (UpdateLog(userID, severityID, PrepMsg(userID, severityID, message, State_Warn, className, functionName), State_Warn, EventLogEntryType.Warning))
             {
                 return(true);
             }
         }
         ILogger altLogger = LoggerFactory.createAlternateLogger();
         return(altLogger.WriteToWarningLog(userID, severityID, className, functionName, message));
     }
     catch (Exception ex)
     {
         ClassForProblemResolutionOnly obj = new ClassForProblemResolutionOnly();
         obj.WriteToEventLog(ex);
         return(false);
     }
 }
Example #2
0
        /// <summary>
        /// Updates the File with the message.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private bool UpdateFile(string message)
        {
            FileStream   fileStream;
            StreamWriter streamWriter;

            try
            {
                lock (this)       //Afzal
                {
                    rwl.AcquireWriterLock(Timeout.Infinite);
                    /*10/11/04: Day change should create new log file */
                    AdjustLoggerFileNamewithDate();

                    if (File.Exists(LoggerFile))
                    {
                        streamWriter = File.AppendText(LoggerFile);
                    }
                    else
                    {
                        fileStream   = File.Open(LoggerFile, FileMode.OpenOrCreate, FileAccess.Write);
                        streamWriter = new StreamWriter(fileStream);
                    }
                    streamWriter.Write(message);
                    streamWriter.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ClassForProblemResolutionOnly obj = new ClassForProblemResolutionOnly();
                obj.WriteToEventLog(ex);
                return(false);
            }
            finally
            {
                rwl.ReleaseWriterLock();
                fileStream   = null;
                streamWriter = null;
            }
        }
Example #3
0
 /// <summary>
 /// Writes a custom message to the Log.
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 private void AdjustLoggerFileNamewithDate()
 {
     try
     {
         int dayofYear;
         dayofYear = DateTime.Now.DayOfYear;
         if (_dayofYear != dayofYear)
         {
             AppSettingsReader reader  = new AppSettingsReader();
             StringBuilder     builder = new StringBuilder();
             LoggerFile = (string)reader.GetValue(LOGGER_FILE, typeof(string));
             builder.Append(LoggerFile);
             builder.Append(DateTime.Now.ToString("MM_dd_yyyy", DateTimeFormatInfo.InvariantInfo));
             builder.Append(".txt");
             LoggerFile = builder.ToString();
             _dayofYear = dayofYear;
         }
     }
     catch (Exception ex)
     {
         ClassForProblemResolutionOnly obj = new ClassForProblemResolutionOnly();
         obj.WriteToEventLog(ex);
     }
 }