Пример #1
0
        public void Throw(LogType type, string message, StackFrame stackFrame, StackTrace stackTrace, CacheType cache)
        {
            DebugInfo value = add(type, message, stackFrame, stackTrace, cache, false);

            throw new Exception(value == null ? type.ToString() : value.ToString());
        }
Пример #2
0
        /// <summary>
        /// 日志写入
        /// </summary>
        private void output()
        {
            DebugInfo        value = null;
            FileStreamWriter fileStream;

            do
            {
                while (System.Threading.Interlocked.CompareExchange(ref debugLock, 1, 0) != 0)
                {
                    AutoCSer.Threading.ThreadYield.Yield(AutoCSer.Threading.ThreadYield.Type.FileLogExchangeDebug);
                }
                if (newDebugs.IsEmpty)
                {
                    System.Threading.Interlocked.Exchange(ref debugLock, 0);
                    return;
                }
                debugs.Exchange(ref newDebugs);
                System.Threading.Interlocked.Exchange(ref debugLock, 0);
                do
                {
                    try
                    {
                        while ((value = debugs.PopOnly()) != null)
                        {
                            switch (value.CacheType)
                            {
                            case CacheType.Queue:
                                HashString cacheKey = value.ToString();
                                if (cache.Get(ref cacheKey, false))
                                {
                                    fileStream = null;
                                }
                                else
                                {
                                    cache.UnsafeAdd(ref cacheKey, true);
                                    if (cache.Count > maxCacheCount)
                                    {
                                        cache.UnsafePopNode();
                                    }
                                    fileStream = this.fileStream;
                                }
                                break;

                            case CacheType.Last:
                                HashString key = value.ToString();
                                if (key.Equals(ref lastCache))
                                {
                                    fileStream = null;
                                }
                                else
                                {
                                    lastCache  = key;
                                    fileStream = this.fileStream;
                                }
                                break;

                            default: fileStream = this.fileStream; break;
                            }
                            if (fileStream != null)
                            {
                                if (value.Type == LogType.Flush)
                                {
                                    fileStream.Flush();
                                }
                                else
                                {
                                    string log = @"
" + Date.NowTime.Now.toString() + " : " + value.ToString() + @"
";
#if XAMARIN
                                    Trace.Console(log);
                                    if (fileStream.WriteNotEmpty(log) != -1 && (value.Type & LogType.Flush) != 0)
                                    {
                                        fileStream.Flush();
                                    }
#else
                                    if (fileStream.WriteNotEmpty(log) >= MaxSize && MaxSize > 0)
                                    {
                                        moveBak();
                                    }
                                    else if ((value.Type & LogType.Flush) != 0)
                                    {
                                        fileStream.Flush();
                                    }
#endif
                                }
                            }
                            pulseWait(value);
                        }
                        goto END;
                    }
                    catch
                    {
                        pulseWait(value);
                        CatchCount.Add(CatchCount.Type.Log_Output);
                    }
                }while (true);
END:
                debugs.SetHeaderNextNull();
            }while (true);
        }
Пример #3
0
        public void Throw(LogType type, Exception error, string message, CacheType cache)
        {
            DebugInfo value = add(type, error, message, cache, false);

            throw error ?? new Exception(value == null ? type.ToString() : value.ToString());
        }