Esempio n. 1
0
        } // END FUNCTION

        /// <summary>
        /// Returns a filename with a _MMDDYYYYHHNNSS date stamp added to it.
        /// </summary>
        /// <param name="fileName">The name and path of the logfile to modify.</param>
        /// <returns>c:\temp\log.log -> c:\temp\log_01152009015500.log</returns>
        public static string GetDateStampedFileName(string fileName)
        {
            string ext = GetFileExtension(fileName);

            if (ext == string.Empty)
            {
                ext = "log";
            }

            fileName  = fileName.Replace(ext, "");
            fileName += DateStamp.GetDateStamp(false) + ext;

            _FileISDateStamped = true;
            //fileName += "_" + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + DateTime.Now.Year.ToString("0000") + DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00") + ext;
            return(fileName);
        }
Esempio n. 2
0
        public LogFile(string logFilePath, bool appendToFile, LogFileNamingType type)
        {
            if (string.IsNullOrEmpty(_LogFileName))
            {
                _LogFileName = "ServiceLog";
            }

            if (Directory.Exists(logFilePath) && LogFileName.Length > 0)
            {
                switch (type)
                {
                case LogFileNamingType.DateStamped:
                    if (logFilePath.EndsWith(@"\"))
                    {
                        logFilePath += LogFileName + DateStamp.GetDateStamp(false) + ".Log";
                    }
                    else
                    {
                        logFilePath += @"\" + LogFileName + DateStamp.GetDateStamp(false) + ".Log";
                    }
                    break;

                default:
                    if (logFilePath.EndsWith(@"\"))
                    {
                        logFilePath += LogFileName + DateStamp.GetDateStamp(false) + ".Log";
                    }
                    else
                    {
                        logFilePath += @"\" + LogFileName + DateStamp.GetDateStamp(false) + ".Log";
                    }
                    break;
                }
            }
            else
            {
                throw new Exception("FilePath or FileName is not valid!!!");
            }
            _logFilePath     = logFilePath;
            _appendToFile    = appendToFile;
            _logFileNameType = type;
        }