예제 #1
0
        public bool WriteLogEvents(LinkedList <object> logEvents)
        {
            lock (mutex)
            {
                if (!isOpen)
                {
                    return(false);
                }

                if (individualFileLogger == null)
                {
                    if (!CreateNewIndividualLogger())
                    {
                        isOpen = false;
                        return(false);
                    }
                }

                bool isFinished = false;
                bool isOkay     = individualFileLogger.WriteLogEvents(logEvents, out isFinished);

                if (!isOkay)
                {
                    isOpen = false;
                    return(false);
                }

                if (isFinished)
                {
                    individualFileLogger = null;
                }

                return(true);
            }
        }
예제 #2
0
        private bool CreateNewIndividualLogger()
        {
            try
            {
                long          length = 0;
                DirectoryInfo di     = new DirectoryInfo(directory);

                FileInfo oldestFile      = null;
                long     fileSmallestNum = Int64.MaxValue;
                long     fileLargestNum  = Int64.MinValue;
                bool     foundFile       = false;

                foreach (FileInfo fi in di.GetFiles())
                {
                    length += fi.Length;
                    string name        = fi.Name;
                    bool   deleteable  = name.StartsWith("x");
                    int    periodIndex = name.IndexOf('.');
                    foundFile |= deleteable;
                    long serialNum = Int64.Parse(name.Substring(1, periodIndex - 1));
                    if (serialNum < fileSmallestNum && deleteable)
                    {
                        fileSmallestNum = serialNum;
                        oldestFile      = fi;
                    }
                    if (serialNum > fileLargestNum)
                    {
                        fileLargestNum = serialNum;
                    }
                }

                if (length > (long)mbLimitLogDirectory * (long)1000000)
                {
                    File.Delete(oldestFile.FullName);
                }

                if (!foundFile)
                {
                    fileLargestNum = 0;
                }

                individualFileLogger = new CMSIndividualFileLogger();
                string file     = directory + "/x" + (fileLargestNum + 1) + ".gz";
                string tempFile = directory + "/t" + (fileLargestNum + 1) + ".gz";
                if (!individualFileLogger.Init(mbLimitLogFile * 2000000, file, tempFile))
                {
                    return(false);
                }
                return(true);
            }
            catch
            {
            }
            return(false);
        }
예제 #3
0
        public void Close()
        {
            lock (mutex)
            {
                if (!isOpen)
                {
                    return;
                }

                try
                {
                    if (individualFileLogger != null)
                    {
                        individualFileLogger.Close();
                        individualFileLogger = null;
                    }
                }
                catch
                {
                }

                isOpen = false;
            }
        }