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); }
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); } } }
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); }
public bool TryDequeue(out LaobianLog log) { return(_logs.TryDequeue(out log)); }
public void Add(LaobianLog log) { _logs.Enqueue(log); }