using Exceptionless; using log4net; using System; using System.Reflection.Emit; namespace WX.CRM.Common { public class LogHelper { public static ILog log = LogManager.GetLogger(typeof(LogHelper)); public static void Error(Exception ex, string resid = null, string orderid = null, params string[] tags) { var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; log.Error(ex); // 先创建 var eventBuilder = ExceptionlessClient.Default.CreateLog("ErrorMessage"); // 再来慢慢添加 eventBuilder.SetException(ex) .SetProperty("@level", "error") .AddObject("hg-web", appid); if (!string.IsNullOrEmpty(resid)) { eventBuilder.AddTags(resid); } if (!string.IsNullOrEmpty(orderid)) { eventBuilder.AddTags(orderid); } if (tags != null && tags.Length > 0) { eventBuilder.AddTags(tags); } // 最后提交 eventBuilder.Submit(); } public static void Error(string msg, string resid = null, string orderid = null, params string[] tags) { log.Error(msg); var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; // 先创建 var eventBuilder = ExceptionlessClient.Default.CreateLog("ErrorMessage"); // 再来慢慢添加 eventBuilder.SetMessage(msg) .SetProperty("@level", "error") .AddObject("hg-web", appid); if (!string.IsNullOrEmpty(resid)) { eventBuilder.AddTags(resid); } if (!string.IsNullOrEmpty(orderid)) { eventBuilder.AddTags(orderid); } if (tags != null && tags.Length > 0) { eventBuilder.AddTags(tags); } // 最后提交 eventBuilder.Submit(); } public static void Error(string msg, Exception ex, string resid = null, string orderid = null, params string[] tags) { log.Error(msg, ex); var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; // 先创建 var eventBuilder = ExceptionlessClient.Default.CreateLog("ErrorMessage"); // 再来慢慢添加 eventBuilder.SetException(ex) .SetMessage(msg) .SetProperty("@level", "error") .AddObject("hg-web", appid); if (!string.IsNullOrEmpty(resid)) { eventBuilder.AddTags(resid); } if (!string.IsNullOrEmpty(orderid)) { eventBuilder.AddTags(orderid); } if (tags != null && tags.Length > 0) { eventBuilder.AddTags(tags); } // 最后提交 eventBuilder.Submit(); } public static void Info(string msg, string resid = null, string orderid = null, params string[] tags) { log.Info(msg); var appid = System.Configuration.ConfigurationManager.AppSettings["appid"]; // 先创建 var eventBuilder = ExceptionlessClient.Default.CreateLog("InfoMessage"); // 再来慢慢添加 eventBuilder.SetMessage(msg) .SetProperty("@level", "info") .AddTags("hg-web", appid); if (!string.IsNullOrEmpty(resid)) { eventBuilder.AddTags(resid); } if (!string.IsNullOrEmpty(orderid)) { eventBuilder.AddTags(orderid); } if (tags != null && tags.Length > 0) { eventBuilder.AddTags(tags); } // 最后提交 eventBuilder.Submit(); } public static void Debug(string msg) { log.Debug(msg); } } }