Ejemplo n.º 1
0
        public void DoLog(string msg, ActionLogTypesEnum logtype = ActionLogTypesEnum.Debug)
        {
            var log = this.Log.GetActionLog();
            log.LogType = logtype;
            log.ActionTime = DateTime.Now;
            log.Remark = msg;
            LogLevel ll = LogLevel.Information;
            switch (logtype)
            {
                case ActionLogTypesEnum.Normal:
                    ll = LogLevel.Information;
                    break;
                case ActionLogTypesEnum.Exception:
                    ll = LogLevel.Error;
                    break;
                case ActionLogTypesEnum.Debug:
                    ll = LogLevel.Debug;
                    break;
                default:
                    break;
            }
            GlobalServices.GetRequiredService<ILogger<ActionLog>>().Log<ActionLog>(ll, new EventId(), log, null, (a, b) => {
                return $@"
===WTM Log===
内容:{a.Remark}
地址:{a.ActionUrl}
时间:{a.ActionTime}
===WTM Log===
";
            });
        }
Ejemplo n.º 2
0
Archivo: BaseVM.cs Proyecto: zyptfy/WTM
        /// <summary>
        /// DoLog
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="logtype"></param>
        public void DoLog(string msg, ActionLogTypesEnum logtype = ActionLogTypesEnum.Debug)
        {
            ActionLog log = Log.Clone() as ActionLog;

            log.LogType    = logtype;
            log.ActionTime = DateTime.Now;
            log.Remark     = msg;
            DC.Set <ActionLog>().Add(log);
            DC.SaveChanges();
        }
Ejemplo n.º 3
0
        public void DoLog(string msg, ActionLogTypesEnum logtype = ActionLogTypesEnum.Debug)
        {
            var log = Log.Clone() as ActionLog;

            log.LogType    = logtype;
            log.ActionTime = DateTime.Now;
            log.Remark     = msg;
            using (var dc = CreateDC())
            {
                dc.Set <ActionLog>().Add(log);
                dc.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void DoLog(string msg, ActionLogTypesEnum logType)
        {
            _vm.Log = new ActionLog();
            _vm.DC  = new DataContext("dologdb" + logType, DBTypeEnum.Memory);
            _vm.DoLog(msg, logType);

            using (var context = new DataContext("dologdb" + logType, DBTypeEnum.Memory))
            {
                var logs = context.Set <ActionLog>().ToList();
                Assert.AreEqual(1, logs.Count());
                Assert.AreEqual(msg, logs[0].Remark);
                Assert.AreEqual(logType, logs[0].LogType);
                Assert.IsTrue(DateTime.Now.Subtract(logs[0].ActionTime).Seconds < 10);
            }
        }
Ejemplo n.º 5
0
        public void Log <TState> (LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (IsEnabled(logLevel))
            {
                ActionLog log = null;
                if (typeof(TState) != typeof(ActionLog))
                {
                    ActionLogTypesEnum ll = ActionLogTypesEnum.Normal;
                    if (logLevel == LogLevel.Trace || logLevel == LogLevel.Debug)
                    {
                        ll = ActionLogTypesEnum.Debug;
                    }
                    if (logLevel == LogLevel.Error || logLevel == LogLevel.Warning || logLevel == LogLevel.Critical)
                    {
                        ll = ActionLogTypesEnum.Exception;
                    }
                    log = new ActionLog
                    {
                        Remark     = formatter?.Invoke(state, exception),
                        CreateTime = DateTime.Now,
                        ActionTime = DateTime.Now,
                        ActionName = "System Log",
                        ModuleName = "System Log",
                        LogType    = ll
                    };
                }
                else
                {
                    log = state as ActionLog;
                }

                if (cs != null)
                {
                    using var dc = cs.CreateDC();
                    if (dc != null)
                    {
                        dc.AddEntity <ActionLog>(log);
                        dc.SaveChanges();
                    }
                }
            }
        }