示例#1
0
 public void Write(LogScope scope, Verbosity verbosity, string source, string text)
 {
     if((int)minimal_verbosity > (int)verbosity || writer == null)
         return;
     lock(writer)
     {
         UpdateScope(scope);
         int lvl = (scope != null) ? scope.Level : 0;
         StringBuilder sb = new StringBuilder();
         for(int i=0; i<lvl; i++)
             sb.Append(" | ");
         string spaces = sb.ToString();
         writer.WriteLine("{0} - {1}: {2} at {3}", spaces, verbosity, text, source);
     }
 }
示例#2
0
        public LogScope(LogScope ParentScope, string Source, string Text)
        {
            this.CreateDateTime = DateTime.Now;
            this.ParentScope = ParentScope;
            this.Source = Source;
            this.Text = Text;
            this.Thread = Thread.CurrentThread;

            if(this.ParentScope != null)
            {
                if(this.ParentScope.ChildScope != null)
                    throw new ApplicationException("Log scope error");
                this.ParentScope.ChildScope = this;
                this.Level = this.ParentScope.Level + 1;
            }
            else
            {
                this.Level = 0;
            }
        }
示例#3
0
 private void UpdateScope(LogScope scope)
 {
     if(last_scope == scope)
         return;
     if(scope == null)
     {
         last_scope = null;
         return;
     }
     last_scope = scope;
     while(last_scope.ParentScope != null)
         last_scope = last_scope.ParentScope;
     while(last_scope != null)
     {
         StringBuilder sb = new StringBuilder();
         for(int i=0; i<scope.Level; i++)
             sb.Append(" | ");
         writer.WriteLine("{0} {1} at {2}", sb.ToString(), scope.Text, scope.Source);
         last_scope = last_scope.ChildScope;
     }
     last_scope = scope;
 }
示例#4
0
文件: Log.cs 项目: langpavel/LPS-old
 private static void ScopeDisposed(object sender, EventArgs e)
 {
     LogScope scope = (LogScope)sender;
     current_scope = scope.ParentScope;
 }
示例#5
0
文件: Log.cs 项目: langpavel/LPS-old
 public static LogScope ScopeSource(string source, string text)
 {
     current_scope = new LogScope(current_scope, source, text);
     current_scope.Disposed += ScopeDisposed;
     return current_scope;
 }