林豪 左 vor 3 Jahren
Ursprung
Commit
bce2dd75cc
2 geänderte Dateien mit 126 neuen und 2 gelöschten Zeilen
  1. 125 0
      WCS_Client/Log/Log.cs
  2. 1 2
      WCS_Client/WCS_Client.csproj

+ 125 - 0
WCS_Client/Log/Log.cs

@@ -0,0 +1,125 @@
+using System;
+using System.IO;
+using System.Windows.Forms;
+
+namespace WCS_Client
+{
+    public class Log
+    {
+        /// 日志文件的路径
+        private string fileLogPath;
+
+        /// 日志文件的名称
+        private string dataFileName;
+
+        public Log(string FileName, string filepath)
+        {
+            this.fileLogPath = filepath;
+            this.dataFileName = FileName + ".txt";
+            //this.dataFileName = DateTime.Now.ToString("yyyyMMdd") + FileName + ".txt";
+        }
+
+        /// <summary>
+        /// 获取或设置日志文件的路径
+        /// </summary>
+        public string FileLogPath
+        {
+            set
+            {
+                this.fileLogPath = value;
+            }
+            get
+            {
+                return this.fileLogPath;
+            }
+        }
+
+        /// <summary>
+        /// 获取或设置日志文件的名称
+        /// </summary>
+        public string DataFileName
+        {
+            set
+            {
+                this.dataFileName = value;
+            }
+            get
+            {
+                return this.dataFileName;
+            }
+        }
+
+        /// <summary>
+        /// 向指定目录中的指定的文件中追加日志文件
+        /// </summary>
+        /// <param name="Message">要写入的内容</param>
+        public void WriteLog(string Message)
+        {
+            this.WriteLog(this.dataFileName, Message);
+        }
+
+        /// <summary>
+        /// 向指定目录中的文件中追加日志文件,日志文件的名称将由传递的参数决定.
+        /// </summary>
+        /// <param name="LogFileName">日志文件的名称,如:mylog.txt ,如果没有自动创建,如果存在将追加写入日志</param>
+        /// <param name="Message">要写入的内容</param>
+        public void WriteLog(string LogFileName, string Message)
+        {
+            //如果日志文件目录不存在,则创建
+            if (!Directory.Exists(this.fileLogPath))
+            {
+                Directory.CreateDirectory(this.fileLogPath);
+            }
+            FileInfo finfo = new FileInfo(this.fileLogPath + LogFileName);
+            try
+            {
+                FileStream fs = new FileStream(this.fileLogPath + LogFileName, FileMode.Append);
+                StreamWriter strwriter = new StreamWriter(fs);
+                try
+                {
+                    strwriter.WriteLine(System.DateTime.Now.ToString() + " " + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + ": " + Message);
+                    strwriter.Flush();
+                }
+                catch (Exception ee)
+                {
+                    Console.WriteLine("日志文件写入失败信息:" + ee.ToString());
+                }
+                finally
+                {
+                    strwriter.Close();
+                    strwriter = null;
+                    fs.Close();
+                    fs = null;
+                }
+            }
+            catch (Exception ee)
+            {
+                Console.WriteLine("日志文件没有打开,详细信息如下:" + ee.ToString());
+            }
+        }
+    }
+
+    public class LogHelper
+    {
+        //private static Log _sys_Log = new Log("系统", "C:\\webapi日志\\");//Application.StartupPath +
+        //private static string mappedPath = System.Web.Hosting.HostingEnvironment.MapPath("~/");
+        private static string mappedPath = Application.StartupPath;
+
+        private static string dt = DateTime.Now.ToString("yyyyMMdd");
+        private static string fileName = dt + " 系统";
+        private static Log _sys_Log = new Log(fileName, mappedPath + "\\Logs\\");
+
+        public static Log Sys_Log
+        {
+            get
+            {
+                if (dt != DateTime.Now.ToString("yyyyMMdd"))
+                {
+                    dt = DateTime.Now.ToString("yyyyMMdd");
+                    _sys_Log = new Log(fileName, mappedPath + "\\Logs\\");
+                }
+                return _sys_Log;
+            }
+        }
+    }
+}

+ 1 - 2
WCS_Client/WCS_Client.csproj

@@ -63,7 +63,7 @@
     <GenerateManifests>true</GenerateManifests>
   </PropertyGroup>
   <PropertyGroup>
-    <SignManifests>true</SignManifests>
+    <SignManifests>false</SignManifests>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="CSkin, Version=16.1.14.2, Culture=neutral, processorArchitecture=MSIL">
@@ -1035,7 +1035,6 @@
       <DependentUpon>Settings.settings</DependentUpon>
       <DesignTimeSharedInput>True</DesignTimeSharedInput>
     </Compile>
-    <None Include="WCS_Client_TemporaryKey.pfx" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="dll\CSkin.dll" />