コード例 #1
0
ファイル: File.cs プロジェクト: mmarzz/AutoCSer
        /// <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);
        }
コード例 #2
0
 private bool Equals(HashedValue other)
 {
     return(HashString.Equals(other.HashString));
 }