Exemple #1
0
    public async Task AddLogAsync(LaobianLog log, CancellationToken cancellationToken = default)
    {
        var site = LaobianSite.Api;

        if (Enum.TryParse(log.LoggerName, true, out LaobianSite temp))
        {
            site = temp;
        }

        await _logFileRepository.AppendLineAsync(
            Path.Combine(site.ToString().ToLowerInvariant(), log.TimeStamp.Year.ToString("D4"),
                         $"{log.TimeStamp.ToDate()}.log"), JsonUtil.Serialize(log), cancellationToken);
    }
Exemple #2
0
 public void Clone(LaobianLog log)
 {
     foreach (var propertyInfo in typeof(LaobianLog).GetProperties())
     {
         var defaultValue = propertyInfo.PropertyType.IsValueType
             ? Activator.CreateInstance(propertyInfo.PropertyType)
             : null;
         var logValue = propertyInfo.GetValue(log);
         if (defaultValue != logValue)
         {
             propertyInfo.SetValue(this, logValue);
         }
     }
 }
Exemple #3
0
    private LaobianLog GetScopeInfo()
    {
        var log = new LaobianLog();

        if (ScopeProvider == null)
        {
            return(log);
        }

        ScopeProvider.ForEachScope((o, otherLog) =>
        {
            if (o is LaobianLog logObj)
            {
                log.Clone(logObj);
            }
        }, log);

        return(log);
    }
Exemple #4
0
 public bool TryDequeue(out LaobianLog log)
 {
     return(_logs.TryDequeue(out log));
 }
Exemple #5
0
 public void Add(LaobianLog log)
 {
     _logs.Enqueue(log);
 }