public async Task AddLog(LogItem logItem, bool writeLog = true) { try { await LogQueueLock.WaitAsync(); if (CompactLog) { var lastLogItem = LogQueue.LastOrDefault(); if ( LogMessageTypeEnum.Progress == logItem.Type && LogMessageTypeEnum.Progress == lastLogItem?.Type ) { LogQueue.Remove(lastLogItem); } } LogQueue.Add(logItem); if (LogQueue.Count() > LogQueueSize) { LogQueue.RemoveAt(0); } } finally { LogQueueLock.Release(); } if (writeLog && null != WriteLog) { var totalLog = await GetLog(); try { if (null != WriteLog) { await WriteLog(totalLog); } } catch (Exception e) { try { Console.WriteLine($"failed to {nameof(WriteLog)}, exception message: {e.Message}"); } catch { } } } }