Exemplo n.º 1
0
        /// <summary>
        /// 打开日志文件写入日志消息
        /// </summary>
        private void FileOpen()
        {
            var __dirPath = Path.Combine(LogPath, FileHelper.GetNameByDate(false));

            DirHelper.DirCreate(__dirPath);
            var __filePath = Path.Combine(__dirPath, GetFilename());

            Writers = new StreamWriter(__filePath, true, Encoding.UTF8);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="dirType">目录类型:1 日志目录名称、2 日志存储路径</param>
        /// <param name="dirNameOrPath">目录名称或路径</param>
        /// <param name="logType">日志生产类型</param>
        private void Initialize(byte dirType, string dirNameOrPath, LogType logType)
        {
            if (this.FLogMessages == null)
            {
                switch (dirType)
                {
                case 0:
                    LogPath = Path.Combine(FileHelper.AppPath, "Logs");
                    break;

                case 1:
                    LogPath = Path.Combine(FileHelper.AppPath, dirNameOrPath);
                    break;

                case 2:
                    LogPath = dirNameOrPath;
                    break;

                default:
                    LogPath = Path.Combine(FileHelper.AppPath, "Logs");
                    break;
                }
                DirHelper.DirCreate(LogPath);
                FTimeSign    = DateTime.Now.AddMinutes(60 - DateTime.Now.Minute);
                FWriterLock  = new object();
                FLogMessages = new Queue <LogMessage>();
                FSemaphore   = new Semaphore(0, int.MaxValue, "Huaxia, Galactic Space Alliance");
                //this.FSemaphore = new Semaphore(0, int.MaxValue, Constants.LogSemaphoreName);
                FState        = true;
                FLogType      = logType;
                LogTailTag    = null;
                FErrorCounted = 0;
                var thread = new Thread(Work)
                {
                    IsBackground = true
                };
                thread.Start();
            }
        }