kazelee
5 小时以前 2d3ee03961d6cfbde70342e8a97bc7b05d0b0dc3
util/LogHelper.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Newtonsoft.Json;
@@ -8,7 +9,7 @@
using NLog.Config;
using NLog.Targets;
namespace HH.WCS.Mobox3.DSZSH {
namespace HH.WCS.Mobox3.DSZSH.util {
    public class LogHelper
    {
        public static Dictionary<string, ILogger> loggers = new Dictionary<string, ILogger>();
@@ -68,18 +69,25 @@
            if (logger != null) {
                logger.Error($"{message}{ex.StackTrace}");
            }
        }
        }
        // ------------
        #region 自定义方法
        public static void Warn(string msg, string preLog = "") {
            Info(preLog + $"出现了[警告]:{msg}", "Warn");
        }
        public static void InfoEx(Exception ex) {
            Info($"发生了异常:{ex.Message}\n{ex.StackTrace}");
        public static void InfoEx(Exception ex, string preLog = "") {
            Info(preLog + $"发生了[异常]:{ex.Message}\n\n{ex.StackTrace}\n", "Exception");
        }
        public static void InfoApi(string apiName, object model) {
            Info($"触发API:{apiName} " + JsonConvert.SerializeObject(model), "API");
            Info($"触发API:{apiName} " + JsonConvert.SerializeObject(model), "API");
        }
        public static void InfoHostToAGV(string taskName, object model) {
            Info($"AGV任务:{taskName}" + JsonConvert.SerializeObject(model), "HosttoagvTask");
        }
        #endregion
    }
    internal class LogFactory
@@ -88,7 +96,7 @@
        /// 通过配置文件配置日志
        /// </summary>
        static LogFactory() {
            var loggerNames = new List<string>() { "HosttoagvTask", "HosttoagvCar", "NDC", "杭奥", "PLC", "API", "OPC" };
            var loggerNames = new List<string>() { "HosttoagvTask", "HosttoagvCar", "NDC", "杭奥", "PLC", "API", "OPC", "Warn", "Exception" };
            LogManager.Configuration = DefaultConfig(loggerNames);
        }