Beispiel #1
0
        /// <summary>
        /// 保存日志的范围
        /// </summary>
        /// <param name="currentSize"></param>
        /// <param name="entity"></param>
        /// <param name="prefix"></param>
        /// <returns></returns>
        private static void LogScopes(LogEntity entity, string prefix)
        {
            if (entity.LogTags != null && entity.LogTags.Count > 0)
            {
                foreach (var item in entity.LogTags)
                {
                    if (AppSetting.GetInstance().LocalLogInfo.IgnoreScopes.Contains(item.Key))
                    {
                        continue;
                    }
                    sb.Append($"[{item.Key}={item.Value}],");
                }
                ;
            }

            sb.Append($"[category={entity.CategoryName}]");

            Log(sb.ToString());
        }
Beispiel #2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state,
                                 Exception exception, Func <TState, Exception, string> formatter)
        {
            if (state == null)
            {
                return;
            }

            var entity = new LogEntity()
            {
                LogDate      = DateTime.Now,
                Level        = logLevel,
                LogTags      = LogScopeProvider.GetInstance().Scopes,
                Message      = state.ToString(),
                ThreadId     = Thread.CurrentThread.ManagedThreadId,
                Exception    = exception,
                CategoryName = categoryName
            };

            XLogger.Log(entity);
        }