Example #1
0
        /// <summary>
        /// <para>Write to the log file in such a way so as to avoid collisions in updating same.</para>
        /// <para>NOTE: THIS PROCESS USES LockWait. IF YOU ARE USING IT ACROSS MACHINES, THERE IS A SLIGHT CHANCE
        /// THAT YOUR PROCESS ID WILL NOT BE UNIQUE. CAVEAT USER.</para>
        /// </summary>
        /// <param name="sMessage">The message to write.</param>
        /// <returns>True if the log file was written.</returns>
        public bool LogWait(string sMessage)
        {
            bool br = false;

            if (FileSemaphore.LockWait(ref fSem) == true)
            {
                if (SimpleLog.Log(sMessage) != null)
                {
                    br = true;
                }
                FileSemaphore.UnLock(ref fSem);
            }
            return(br);
        }
Example #2
0
        /// <summary>
        ///  Returns a NULL string on error, else a copy of what was written to the log file.
        /// </summary>
        /// <param name="sPrefix">What you want to place BEFORE the log entry (e.g. ClassicTime())</param>
        /// <param name="log">The governing instance (log file, etc)</param>
        /// <param name="sMessage">The message to write to the log.</param>
        /// <returns>The pattern written. String is null on error.</returns>
        static public string Log(string sPrefix, ref SimpleLog log, string sMessage)
        {
            string sFinal = sPrefix + " [" + log.sHost + "." + log.sProcessId + "]" + ": " + sMessage;

            try
            {
                System.IO.StreamWriter sw = File.AppendText(log.sLogFile);
                sw.WriteLine(sFinal);
                sw.Flush();
                sw.Close();
            }
            catch (Exception)
            {
                sFinal = null;
                return(sFinal);
            }
            return(sFinal);
        }
Example #3
0
        /// <summary>
        /// The preferred entry point.
        /// </summary>
        /// <param name="sMessage">The message to log.</param>
        /// <returns>The pattern written. String is null on error.</returns>
        static public string Log(string sMessage)
        {
            SimpleLog sl = new SimpleLog();

            return(Log(ClassicTime(), ref sl, sMessage));
        }