示例#1
0
        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);
            }
        }
示例#2
0
 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();
     }
 }
示例#3
0
        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;
                }
            }
        }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        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;
            }
        }
示例#6
0
        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属性");
 }