public void Fatal_Valid_Fact()
        {
            _wrapper.Fatal("This is a Fact");

            _eventArgs.Should().NotBeNull();
            _eventArgs.Name.Should().Be("This is a Fact");
            _eventArgs.Level.Should().Be(LogLevel.Fatal);
        }
Beispiel #2
0
        private void AddLog(string Msg, StackTrace stack = null, string Tittle = "", int TenantId = 0, int UserId = 0, LogType logtype = LogType.Debug, Object Context = null)
        {
            try
            {
                if (stack == null)
                {
                    stack = new StackTrace(true);
                }
                var    methodBase = stack.GetFrame(1).GetMethod();
                Type   stacktype  = methodBase.DeclaringType;
                string fileName   = stacktype.FullName; //文件名
                string methodName = methodBase.Name;    //方法名
                var    logModel   = new LogModel
                {
                    TenantId   = TenantId,
                    UserId     = UserId,
                    Message    = Msg,
                    Title      = Tittle,
                    MethodName = methodName,
                    FileName   = fileName,
                    CodeLine   = "0"
                };
                var jsonValue = JsonConvert.SerializeObject(logModel);
                switch (logtype)
                {
                case LogType.Debug:
                    _log.Debug(jsonValue);
                    break;

                case LogType.Info:
                    _log.Info(jsonValue);
                    break;

                case LogType.Warn:
                    _log.Warn(jsonValue);
                    break;

                case LogType.Error:
                    _log.Error(jsonValue);
                    break;

                case LogType.Fatal:
                    _log.Fatal(jsonValue);
                    break;

                default:
                    _log.Debug(jsonValue);
                    break;
                }
            }
            catch
            {
            }
        }