async Task WriteLogs() { var totalKeepCount = 80; var keepCount = totalKeepCount; var delayMilliseconds = 120; while (true) { WritingClainNode node = null; lock (this) { node = this.Head; this.Head = this.Tail = null; } if (node == null) { if (--keepCount <= 0) { lock (this) { if(this.Head==null) this._WritingTask = null; } return; } } else { keepCount = totalKeepCount; await this.PersistentLogs(node); } await Task.Delay(delayMilliseconds); } }
public async Task PersistentLogsxx(WritingClainNode node) { using (var conn = this.GetOrCreateConnection(this.DbName)) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandText = string.Format(DbLogWriter.CreateTableSql, "itec_"); cmd.ExecuteNonQuery(); } }
public virtual async Task PersistentLogs(WritingClainNode node) { while (node != null) { try { await this.WriteLog(node.Entry); node = node.Next; } catch (Exception ex) { var c = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ForegroundColor = c; } } }
public void RecordLog(LogEntry entry) { entry.LogTime = DateTime.Now; var node = new WritingClainNode(entry); lock (this) { if (Head == null) { Head = Tail = node; } else { Tail.Next = node; Tail = node; } if (_WritingTask == null) { _WritingTask = Task.Run(this.WriteLogs); } } }
public override async Task PersistentLogs(WritingClainNode node) { using (var conn = this.GetOrCreateConnection(this.DbName)) { await conn.OpenAsync(); while (node != null) { var cmd = this.BuildCommand(conn, node.Entry); try { await cmd.ExecuteNonQueryAsync(); } catch (Exception ex) { var c = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ForegroundColor = c; } node = node.Next; } this.Command = null; } }
public override async Task PersistentLogs(WritingClainNode node) { TextWriter stream = null; while (node != null) { try { var entry = node.Entry; GetFileStream(entry, ref stream); await WriteToStream(entry, stream); } catch (Exception ex) { var c = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ForegroundColor = c; } node = node.Next; } if (stream != null) { stream.Dispose(); } }
public Task PersistentLogs(WritingClainNode node) { throw new InvalidOperationException("LogWriterCollection不应该调用该方法,调用该方法前应该检查IsCollection属性"); }