Exemplo n.º 1
0
        /// <summary>
        /// Log a message.
        /// </summary>
        /// <param name="Message">Message to log.</param>
        /// <param name="Severity">Error severity level.</param>
        public void RecordMessage(string message, DBLog.MessageType severity)
        {
            // Log type is again set to assign the log name and location to the
            // logger if it was not assigned earlier
            this.LogType = this._logType;

            this._fileLogger.RecordMessage(message, severity);
        }
        /// <summary>
        /// Log a message.
        /// </summary>
        /// <param name="Message">Message to log. </param>
        /// <param name="Severity">Error severity level. </param>
        public void RecordMessage(string message, DBLog.MessageType severity)
        {
            FileStream    fileStream = null;
            StreamWriter  writer     = null;
            StringBuilder filePath   = new StringBuilder();

            // create a resource manager to read the error message from resource file
            ResourceManager resourceManager
                = new ResourceManager(BASE_NAME, Assembly.GetExecutingAssembly());

            try
            {
                // check if directory for log files exists or not
                if (!Directory.Exists(_fileLocation))
                {
                    // if not then show the error message from the resource file
                    string errorMessage = MSG_BAD_PATH;
                    string correctPath  = CORRECT_PATH;
                    correctPath  = string.Concat(correctPath, _fileLocation);
                    errorMessage = string.Concat(errorMessage, "\r\n", correctPath);
                }

                // Builds file path
                filePath.Append(this._fileLocation);
                filePath.Append(this._fileName);

                // creates a filestream for the specified file
                fileStream = new FileStream(filePath.ToString(), FileMode.OpenOrCreate, FileAccess.Write);

                // creates text writer for writing characters to a file stream
                writer = new StreamWriter(fileStream);

                // Set the file pointer to the end of the file
                writer.BaseStream.Seek(0, SeekOrigin.End);

                // Force the write to the underlying file
                writer.WriteLine(message);
                writer.Flush();
            }
            finally
            {
                // if writer is not null then close the writer
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Log an exception.
        /// This method also collects additional information about running process or application to store along with error.
        /// </summary>
        /// <param name="sourceApplication">Application/Process using logger.</param>
        /// <param name="message">Extra information regarding the process running.</param>
        /// <param name="exception">Exception thrown by process.</param>
        /// <param name="Severity">Error severity level.</param>
        public void RecordMessage(string sourceApplication, string message, Exception exception, DBLog.MessageType severity)
        {
            // Log type is again set to assign the log name and location to the
            // logger if it was not assigned earlier
            this.LogType = this._logType;

            this._dbLogger.RecordMessage(sourceApplication, message, exception, severity);
        }
 /// <summary>
 /// Log an exception.
 /// </summary>
 /// <param name="Message">Exception to log. </param>
 /// <param name="Severity">Error severity level. </param>
 public void RecordMessage(Exception message, DBLog.MessageType severity)
 {
     // log message in log file
     this.RecordMessage(message.Message, severity);
     this.RecordMessage(message.StackTrace, severity);
 }