Beispiel #1
0
        internal static void NewLogFile()
        {
            Random random = new Random();

            OperatingID = random.Next();//ID Varied, task should exit immediately.
            //if (LogTask != null) thread.;
            var         Now = DateTime.Now;
            StorageFile storageFile;

            ApplicationStorage.Logs.CreateFile(TrustedInstaller, $"{Now.Year}-{Now.Month}-{Now.Day}-{Now.Minute}-{Now.Second}-{Now.Millisecond}.log", out storageFile);
            CurrentLogFile  = storageFile.ItemPath;
            LogFile         = new FileWR(storageFile.ToFileInfo(TrustedInstaller));
            thread          = new Thread(new ThreadStart(delegate() { LogWatcher(); }));
            thread.Priority = ThreadPriority.Lowest;
            thread.Start();
            //LogTask = Task.Run(LogWatcher);
        }
Beispiel #2
0
        public LWMSTraceListener(string BasePath)
        {
            LogDir = ApplicationStorage.Logs.ItemPath;
            var         Now = DateTime.Now;
            StorageFile storageFile;

            ApplicationStorage.Logs.CreateFile(TrustedInstaller, $"{Now.Year}-{Now.Month}-{Now.Day}-{Now.Minute}-{Now.Second}-{Now.Millisecond}.log", out storageFile);
            CurrentLogFile = storageFile.ItemPath;
            LogFile        = new FileWR(storageFile.ToFileInfo(TrustedInstaller));
            Random random = new Random();

            OperatingID     = random.Next();
            thread          = new Thread(new ThreadStart(delegate() { LogWatcher(); }));
            thread.Priority = ThreadPriority.Lowest;
            thread.Start();
            //LogTask = Task.Run(LogWatcher);
        }
Beispiel #3
0
        /// <summary>
        /// LogWatcher, will watch ContentToLog and write them to UsingWR.
        /// </summary>
        static void LogWatcher()
        {
            IBaseWR UsingWR = LogFile;
            int     TID     = OperatingID;

            while (TID == OperatingID)
            {
                if (WriteToFile == true)
                {
                    if (RemainContents != 0)
                    {
                        if (ContentToLog.IsEmpty == false)
                        {
                            string content;
                            if (ContentToLog.TryDequeue(out content))
                            {
                                UsingWR.Write(content);
                                UsingWR.Flush();

                                RemainContents--;
                                if (_MAX_LOG_SIZE != -1)
                                {
                                    if (UsingWR.Length >= _MAX_LOG_SIZE)
                                    {
                                        NewLogFile();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Thread.Sleep(_LOG_WATCH_INTERVAL);
                    }
                }
                else
                {
                    Thread.Sleep(_LOG_WATCH_INTERVAL);
                }
            }
            UsingWR.Dispose();
        }