public void ThrowReal(Exception exception, string message, TmphCacheType cache)
 {
     if (exception != null && exception.Message.StartsWith(ExceptionPrefix, StringComparison.Ordinal)) exception = null;
     if (exception == null)
     {
         if (message != null) ThrowReal(message, true, cache);
     }
     else
     {
         var value = new TmphDebug
         {
             Exception = exception,
             Message = message
         };
         if (cache == TmphCacheType.None || CheckCache(value, cache == TmphCacheType.Queue)) realOutput(value);
         throw exception != null
             ? new Exception(ExceptionPrefix + message, exception)
             : new Exception(ExceptionPrefix + message);
     }
 }
 public void ThrowReal(string message, bool isStackTrace, TmphCacheType cache)
 {
     var value = new TmphDebug
     {
         StackTrace = isStackTrace ? new StackTrace() : null,
         StackFrame = isStackTrace ? null : new StackFrame(1),
         Message = message
     };
     if (cache == TmphCacheType.None || CheckCache(value, cache == TmphCacheType.Queue)) realOutput(value);
     throw new Exception(ExceptionPrefix + message);
 }
 public void ThrowReal(TmphExceptionType exceptionType)
 {
     var value = new TmphDebug
     {
         StackTrace = new StackTrace(),
         exceptionType = exceptionType
     };
     if (CheckCache(value, true)) realOutput(value);
     throw new Exception(ExceptionPrefix + value);
 }
 public void Add(string message, bool isStackTrace, TmphCacheType cache)
 {
     var value = new TmphDebug
     {
         StackTrace = isStackTrace ? new StackTrace() : null,
         StackFrame = isStackTrace ? null : new StackFrame(1),
         Message = message
     };
     if (cache == TmphCacheType.None || CheckCache(value, cache == TmphCacheType.Queue))
         output(value);
 }
 public void Add(Exception error, string message, TmphCacheType cacheType)
 {
     if (error != null && error.Message.StartsWith(ExceptionPrefix, StringComparison.Ordinal))
         error = null;
     if (error == null)
     {
         if (message != null)
             Add(message, true, cacheType);
     }
     else
     {
         var value = new TmphDebug
         {
             Exception = error,
             Message = message
         };
         if (cacheType == TmphCacheType.None || CheckCache(value, cacheType == TmphCacheType.Queue)) output(value);
     }
 }
 private bool CheckCache(TmphDebug value, bool isQueue)
 {
     TmphHashString key = value.ToString();
     if (isQueue)
     {
         TmphInterlocked.NoCheckCompareSetSleep0(ref cacheLock);
         try
         {
             if (tmphFifoPriorityQueue.Get(key, false))
                 return false;
             tmphFifoPriorityQueue.Set(key, true);
             if (tmphFifoPriorityQueue.Count > maxCacheCount)
                 tmphFifoPriorityQueue.Pop();
         }
         finally
         {
             cacheLock = 0;
         }
         return true;
     }
     if (key.Equals(lastCache))
         return false;
     lastCache = key;
     return true;
 }
 private void realOutput(TmphDebug value)
 {
     if (isDisposed == 0)
     {
         if (fileStream == null)
             Console.WriteLine(@" " + TmphDate.NowSecond.toString() + " : " + value);
         else
         {
             var data = fileStream.GetBytes(@" " + TmphDate.NowSecond.toString() + " : " + value + @" ");
             if (Interlocked.CompareExchange(ref fileLock, 1, 0) != 0)
             {
                 Thread.Sleep(0);
                 while (Interlocked.CompareExchange(ref fileLock, 1, 0) != 0)
                     Thread.Sleep(1);
             }
             try
             {
                 if (fileStream.UnsafeWrite(data) >= MaxSize && MaxSize > 0)
                     MoveBakPri();
                 else
                     fileStream.Flush(true);
             }
             finally
             {
                 fileLock = 0;
             }
         }
     }
 }