林豪 左 2 년 전
부모
커밋
2a603a5547
1개의 변경된 파일34개의 추가작업 그리고 2개의 파일을 삭제
  1. 34 2
      WCS.Core/DataTrans/DataBlock.cs

+ 34 - 2
WCS.Core/DataTrans/DataBlock.cs

@@ -3,6 +3,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.IO;
 using System.Linq;
 using System.Reflection;
 using System.Runtime.InteropServices;
@@ -35,6 +36,7 @@ namespace WCS.Core
         public void DataRefresh()
         {
             var sw = new Stopwatch();
+            string msg = "";
             try
             {
                 if (Entity.NOUPDATE && Data != null)
@@ -66,7 +68,9 @@ namespace WCS.Core
                     }
                     catch (Exception ex)
                     {
-                        Console.WriteLine($"{Entity.PLC.NAME}{Entity.PLC.IP}{Entity.NO}:{ex.Message}--DataBlock69");
+                        msg = $"{Entity.PLC.NAME}{Entity.PLC.IP}{Entity.NO}:{ex.Message}--DataBlock69";
+                        Console.WriteLine(msg);
+                        Log(msg);
                         Console.ResetColor();
                     }
                 }
@@ -75,7 +79,10 @@ namespace WCS.Core
             {
                 sw.Stop();
                 failed = true;
-                throw;
+                msg = $"{Entity.PLC.NAME}{Entity.PLC.IP}{Entity.NO}:{ex.Message}--DataBlock78";
+                Console.WriteLine(msg);
+                Log(msg);
+                Console.ResetColor();
             }
             finally
             {
@@ -88,6 +95,31 @@ namespace WCS.Core
             }
         }
 
+        private object lockobj;
+        private string logPath = @"Log\" + "DataRefresh" + @"\";
+
+        protected void Log(string msg)
+        {
+            lock (lockobj)
+            {
+                try
+                {
+                    var str = "-----------" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss:fff") + "-----------\r\n";
+                    str += msg;
+                    if (!Directory.Exists(logPath))
+                        Directory.CreateDirectory(logPath);
+                    var file = logPath + DateTime.Now.ToString("yyyyMMdd") + ".log";
+                    var writer = File.AppendText(file);
+                    writer.WriteLine(str);
+                    writer.Flush();
+                    writer.Close();
+                }
+                catch (Exception ex)
+                {
+                }
+            }
+        }
+
         public PlcItem<T> Regist<T>(string objid, string name, int start, byte arrLen = 1, byte strLen = 0)
         {
             var t = typeof(T);