From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.Share/IO/OperationLog.cs |  315 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 315 insertions(+), 0 deletions(-)

diff --git a/HotelPms.Share/IO/OperationLog.cs b/HotelPms.Share/IO/OperationLog.cs
new file mode 100644
index 0000000..19408fe
--- /dev/null
+++ b/HotelPms.Share/IO/OperationLog.cs
@@ -0,0 +1,315 @@
+using HotelPms.Share.Util;
+using System;
+using System.Globalization;
+using System.IO;
+using System.Text;
+using System.Threading;
+
+namespace HotelPms.Share.IO
+{
+    public class OperationLog
+    {
+        /// ****************************** Description *******************************
+        /// ���V�X�e������
+        /// �@�ėp�N���X
+        /// ���T�v
+        /// �@�ȒPOpeLog���s
+        /// ������
+        /// �@2016/02/28  ���؁@����    �V�K�쐬
+        /// ****************************** Declarations ******************************
+
+        #region  �����������@Declartions�@����������
+
+        public enum LogLevelType : int
+        { 
+            Normal = 0,
+            Level1,
+            Level2,
+            Level3,
+            Level4,
+            Level5,
+            Level6,
+            /// <summary>
+            /// �ʏ�SQL���O
+            /// </summary>
+            Level7,
+            /// <summary>
+            /// �^�C�}�[�̏��񏈗�SQL���O
+            /// </summary>
+            Level8,
+            /// <summary>
+            /// DB��new MsSqlNet���x��
+            /// </summary>
+            Level9,
+        }
+
+        private static string LogLevelFile = System.AppDomain.CurrentDomain.BaseDirectory + @"LogLevel.dat";
+        private static OperationLog? m_Default;
+        public static object SyncRoot = new object();
+        private string rootPath = System.AppDomain.CurrentDomain.BaseDirectory + @"OpeLog" + Path.DirectorySeparatorChar;
+        private long m_FileMaxSize = 512;  //�P�ʁFKB
+        private int m_FileIndex = 1;
+        private bool m_Enabled = true;
+        public event MessageEventHandler? OutPut;
+
+        #endregion
+
+        #region  �����������@Property�@����������
+
+        private LogLevelType m_Level = LogLevelType.Normal;
+
+        public LogLevelType Level
+        {
+            get { return m_Level; }
+            set { m_Level = value; }
+        }
+
+        public static OperationLog Instance
+        {
+            get 
+            {
+                if (m_Default == null) { m_Default = new OperationLog(System.AppDomain.CurrentDomain.BaseDirectory + @"OpeLog" + Path.DirectorySeparatorChar + Environment.MachineName + "_" + Environment.UserName + Path.DirectorySeparatorChar, 512); }
+                return m_Default;
+            }
+        }
+
+        public long FileMaxSize
+        {
+            set { m_FileMaxSize = value; }
+            get { return m_FileMaxSize; }
+        }
+
+        /// <summary>
+        /// Log����邩�ǂ���
+        /// </summary>
+        public string RootPath
+        {
+            get { return rootPath; }
+            set { rootPath = value; }
+        }
+
+        public bool Enabled
+        {
+            get { return m_Enabled; }
+            set { m_Enabled = value; }
+        }
+
+        #endregion
+
+        #region  �����������@Class Event�@����������
+
+        /// <summary>
+        /// �R���X�g���N�^
+        /// </summary>
+        /// <param name="currentType">�@�\ID����(�ʏ�SystemLog����`����Ă����ʁA�N���X)</param>
+        /// <param name="running">�����I�Ƀ��O�������邩�ǂ���</param>
+        /// <param name="rootPath"></param>
+        /// <param name="maxSize">�P�ʁFKB</param>
+        public OperationLog(string rootPath, long maxSize)
+        {
+            if (rootPath.Length > 0) { this.rootPath = rootPath; }
+            this.m_FileMaxSize = maxSize;
+            if (File.Exists(LogLevelFile)) { m_Level = (LogLevelType)CConvert.ToInt(File.ReadAllText(LogLevelFile, Encoding.UTF8)); }
+            InitLogger();
+        }
+
+        #endregion
+
+        #region  �����������@Public Functions�@����������        
+
+        /// <summary>
+        /// �V�X�e�����Ԃ���delayMonth���O�̃t�H���_���폜����
+        /// </summary>
+        /// <param name="delayMonth"></param>
+        public void ClearLog(int delayMonth)
+        {
+            try
+            {
+                string[] dirList = Directory.GetDirectories(rootPath);
+
+                foreach (string curDir in dirList)
+                {
+                    if (curDir.Substring(curDir.Length - 6, 6).CompareTo(DateTime.Now.Date.AddMonths(-delayMonth).ToString("yyyyMM")) <= 0)
+                    {
+                        FileOperation.DeleteDir(curDir);
+                    }
+                }
+            }
+            catch
+            {
+            }
+        }
+
+        /// <summary>
+        /// �V�X�e�����Ԃ���delayDay���O�̃t�H���_�ƃt�@�C�����폜����
+        /// </summary>
+        /// <param name="delayMonth"></param>
+        public void ClearLogByDay(int delayDay)
+        {
+            try
+            {
+                string beginYM = DateTime.Now.Date.AddDays(-delayDay).ToString("yyyyMM");
+                int beginD = CConvert.ToInt(DateTime.Now.Date.AddDays(-delayDay).ToString("dd"));
+
+                string[] dirList = Directory.GetDirectories(rootPath);
+
+                foreach (string curDir in dirList)
+                {
+                    if (curDir.Substring(curDir.Length - 6, 6).CompareTo(beginYM) < 0)
+                    {
+                        FileOperation.DeleteDir(curDir);
+                    }
+                    else if (curDir.Substring(curDir.Length - 6, 6).CompareTo(beginYM) == 0)
+                    {
+                        //���t���폜
+                        string[] fileList = Directory.GetFiles(curDir);
+                        foreach (string file in fileList)
+                        {
+                            if (CConvert.ToInt(Path.GetFileNameWithoutExtension(file).Substring(0, 2)) < beginD)
+                            {
+                                FileOperation.Delete(file);
+                            }
+                        }
+                    }
+                }
+            }
+            catch
+            {
+            }
+        }
+
+        #endregion
+
+        #region  �����������@Private Functions�@����������
+
+        private void RaiseOutputEvent(string msg)
+        {
+            if (OutPut != null) { OutPut(this, new MessageEventArgs(msg)); }
+        }
+
+        private string GetFileName()
+        {
+            if (m_FileMaxSize == 0) { return DateTime.Now.Day.ToString("00", NumberFormatInfo.CurrentInfo); }
+
+            string dir = rootPath + DateTime.Now.ToString("yyyyMM");
+            string fileBase = DateTime.Now.Day.ToString("00", NumberFormatInfo.CurrentInfo) + "_{0}";
+
+            while (true)
+            {
+                string fileName = string.Format(fileBase, m_FileIndex);
+                string fileFullPath = dir + Path.DirectorySeparatorChar + fileName + ".log";
+                if (!File.Exists(fileFullPath))
+                {
+                    File.WriteAllText(fileFullPath, "��������,���e" + Environment.NewLine, Encoding.UTF8);
+                    return fileName;
+                }
+
+                FileInfo fileInfo = new FileInfo(fileFullPath);
+                if (fileInfo.Length < (m_FileMaxSize * 1024)) { return fileName; }
+                RaiseOutputEvent("GetFileName�F" + fileFullPath);
+                m_FileIndex++;
+            }
+        }
+
+        /// <summary>
+        /// logger������
+        /// </summary>
+        private void InitLogger()
+        {
+            try
+            {
+                string dir = rootPath + DateTime.Now.ToString("yyyyMM");
+                if (!Directory.Exists(dir))
+                {
+                    Directory.CreateDirectory(dir);
+                    m_FileIndex = 1;
+                }
+                string filePath = dir + Path.DirectorySeparatorChar + GetFileName() + ".log";
+                if (!File.Exists(filePath))
+                {
+                    File.WriteAllText(filePath, "��������,���e" + Environment.NewLine, Encoding.UTF8);
+                }
+                //this.projectName = Assembly.GetCallingAssembly().ManifestModule.Name;
+            }
+            catch (Exception ex)
+            {
+                RaiseOutputEvent("InitLogger�F" + ex.Message);
+            }
+        }
+
+        public void WriteLog(string message)
+        {
+            WriteLog(message, LogLevelType.Normal);
+        }
+
+        public void WriteLog(string message, LogLevelType level)
+        {
+            if (!m_Enabled) { return; }
+            if ((int)m_Level < (int)level) { return; }
+
+            lock (SyncRoot)
+            {
+                InitLogger();   //���������
+
+                try
+                {
+                    string filePath = rootPath + DateTime.Now.ToString("yyyyMM") + Path.DirectorySeparatorChar + GetFileName() + ".log";
+                    using (StreamWriter sw = new StreamWriter(filePath, true, Encoding.UTF8))
+                    {
+                        sw.WriteLine(string.Format("�y{0}�z{1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss fff"), message));
+                        sw.Close();
+                    }
+                }
+                catch (Exception ex)
+                {
+                    RaiseOutputEvent("WriteLog�F" + ex.Message);
+                }
+            }
+        }
+
+        public static void Write(string msg)
+        {
+            Write(msg, LogLevelType.Normal);
+        }
+
+        public static void Write(string msg, LogLevelType level)
+        {
+            try
+            {
+                //�񓯊�����
+                ParameterizedThreadStart theradStart = new ParameterizedThreadStart(delegate(object data) 
+                {
+                    LogInfo item = data as LogInfo;
+                    OperationLog.Instance.WriteLog(item.Message, item.Level);
+                });
+                Thread tr = new Thread(theradStart);
+                tr.Start(new LogInfo(msg, level));
+            }
+            catch
+            {
+                return;
+            }
+        }
+
+        public static void Clear(int delayMonth)
+        {
+            try
+            {
+                //�񓯊�����
+                ParameterizedThreadStart theradStart = new ParameterizedThreadStart(delegate(object data)
+                {
+                    OperationLog.Instance.ClearLog(int.Parse(data.ToString()));
+                });
+                Thread tr = new Thread(theradStart);
+                tr.Start(delayMonth);
+            }
+            catch
+            {
+                return;
+            }
+        }
+
+
+        #endregion
+    }
+}

--
Gitblit v1.10.0