zoukankan      html  css  js  c++  java
  • HearthBuddy 日志模块

    // Triton.Common.LogUtilities.CustomLogger
    // Token: 0x04000BD8 RID: 3032
    private Level level_0 = Level.All;
    // Token: 0x04000BD9 RID: 3033
    private Level level_1 = Level.Emergency;
    // Token: 0x06001779 RID: 6009 RVA: 0x000D3D08 File Offset: 0x000D1F08
    public CustomLogger(string path, string prefix, Level minLevel, Level maxLevel)
    {
        this.string_0 = prefix;
        this.level_0 = (minLevel ?? Level.All);
        this.level_1 = (maxLevel ?? Level.Emergency);
        Directory.CreateDirectory(path);
        PatternLayout patternLayout = new PatternLayout("%-4utcdate [%thread] %-5level %logger{1} %ndc - %message%newline");
        DateTime now = DateTime.Now;
        this.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), string.Format("{6}\{7} {5} {0:0000}-{1:00}-{2:00} {3:00}.{4:00}.txt", new object[]
        {
            now.Year,
            now.Month,
            now.Day,
            now.Hour,
            now.Minute,
            Process.GetCurrentProcess().Id,
            path,
            this.string_0
        }));
        FileAppender fileAppender = new FileAppender
        {
            File = this.FileName,
            Layout = patternLayout,
            LockingModel = new FileAppender.MinimalLock()
        };
        fileAppender.AddFilter(new LevelRangeFilter
        {
            LevelMin = this.level_0,
            LevelMax = this.level_1,
            AcceptOnMatch = true
        });
        patternLayout.ActivateOptions();
        fileAppender.ActivateOptions();
        AsyncAppender asyncAppender = new AsyncAppender();
        asyncAppender.AddAppender(fileAppender);
        asyncAppender.ActivateOptions();
        Hierarchy hierarchy = (Hierarchy)LogManager.CreateRepository(this.string_0);
        hierarchy.Root.AddAppender(asyncAppender);
        hierarchy.Configured = true;
    }
    // Triton.Common.LogUtilities.CustomLogger
    // Token: 0x0600177C RID: 6012 RVA: 0x000D3F1C File Offset: 0x000D211C
    public void AddWpfListener(ScrollViewer scrollViewer, RichTextBox rtbLog)
    {
        PatternLayout patternLayout = new PatternLayout("%message");
        this.wpfRtfAppender_0 = new WpfRtfAppender(scrollViewer, rtbLog)
        {
            Layout = patternLayout
        };
        LevelRangeFilter levelRangeFilter = new LevelRangeFilter();
        levelRangeFilter.LevelMin = this.level_0;
        levelRangeFilter.LevelMax = this.level_1;
        this.wpfRtfAppender_0.AddFilter(levelRangeFilter);
        patternLayout.ActivateOptions();
        this.wpfRtfAppender_0.ActivateOptions();
        AsyncAppender asyncAppender = new AsyncAppender();
        asyncAppender.AddAppender(this.wpfRtfAppender_0);
        asyncAppender.ActivateOptions();
        ((Hierarchy)LogManager.GetRepository(this.string_0)).Root.AddAppender(asyncAppender);
    }

    如何把日志输出到MainWindow

    // Hearthbuddy.Windows.MainWindow
    // Token: 0x0400014B RID: 331
    private bool bool_0 = true;
    // Token: 0x04000150 RID: 336
    private readonly Stopwatch stopwatch_0 = new Stopwatch();
    // Token: 0x060001FE RID: 510 RVA: 0x00003C20 File Offset: 0x00001E20
    public MainWindow()
    {
        this.InitializeComponent();
        Logger.AddWpfListener(this.scrollViewer_0, this.richTextBox_0);
    }
    // Triton.Common.LogUtilities.Logger
    // Token: 0x06001782 RID: 6018 RVA: 0x00010FE5 File Offset: 0x0000F1E5
    public static void AddWpfListener(ScrollViewer scrollViewer, RichTextBox rtbLog)
    {
        Logger.customLogger_0.AddWpfListener(scrollViewer, rtbLog);
    }
    // Triton.Common.LogUtilities.CustomLogger
    // Token: 0x0600177C RID: 6012 RVA: 0x000D3F24 File Offset: 0x000D2124
    public void AddWpfListener(ScrollViewer scrollViewer, RichTextBox rtbLog)
    {
        PatternLayout patternLayout = new PatternLayout("%date{yyyy-MM-dd HH:mm:ss.fffzzz} [%thread] %-5level %logger - %message%newline");
        this.wpfRtfAppender_0 = new WpfRtfAppender(scrollViewer, rtbLog)
        {
            Layout = patternLayout
        };
        LevelRangeFilter levelRangeFilter = new LevelRangeFilter();
        levelRangeFilter.LevelMin = this.level_0;
        levelRangeFilter.LevelMax = this.level_1;
        this.wpfRtfAppender_0.AddFilter(levelRangeFilter);
        patternLayout.ActivateOptions();
        this.wpfRtfAppender_0.ActivateOptions();
        AsyncAppender asyncAppender = new AsyncAppender();
        asyncAppender.AddAppender(this.wpfRtfAppender_0);
        asyncAppender.ActivateOptions();
        ((Hierarchy)LogManager.GetRepository(this.string_0)).Root.AddAppender(asyncAppender);
    }

    输出日志的颜色控制

    // Triton.Common.LogUtilities.WpfRtfAppender
    // Token: 0x060017AA RID: 6058 RVA: 0x000D40E4 File Offset: 0x000D22E4
    private void method_0(object sender, EventArgs e)
    {
        try
        {
            this.dispatcherTimer_0.Stop();
            SolidColorBrush solidColorBrush = this.InfoBrush;
            StringBuilder stringBuilder = new StringBuilder();
            Action<StringBuilder, SolidColorBrush> action = new Action<StringBuilder, SolidColorBrush>(this.method_1);
            if (this.paragraph_0 == null)
            {
                this.richTextBox_0.Document.Blocks.Clear();
                this.paragraph_0 = new Paragraph();
                this.paragraph_0.Margin = new Thickness(0.0);
                this.richTextBox_0.Document.Blocks.Add(this.paragraph_0);
            }
            if (this.int_0 >= 2000)
            {
                this.paragraph_0.Inlines.Clear();
                this.int_0 = 0;
            }
            LoggingEvent loggingEvent;
            while (this.concurrentQueue_0.TryDequeue(out loggingEvent))
            {
                loggingEvent.Fix = FixFlags.All;
                string value = base.RenderLoggingEvent(loggingEvent);
                string name = loggingEvent.Level.Name;
                SolidColorBrush solidColorBrush2;
                if (!(name == "DEBUG"))
                {
                    if (!(name == "ERROR"))
                    {
                        if (!(name == "WARN"))
                        {
                            solidColorBrush2 = this.InfoBrush;
                        }
                        else
                        {
                            solidColorBrush2 = this.WarnBrush;
                        }
                    }
                    else
                    {
                        solidColorBrush2 = this.ErrorBrush;
                    }
                }
                else
                {
                    solidColorBrush2 = this.DebugBrush;
                }
                if (!object.Equals(solidColorBrush2, solidColorBrush))
                {
                    action(stringBuilder, solidColorBrush);
                    stringBuilder.Clear();
                    solidColorBrush = solidColorBrush2;
                }
                stringBuilder.AppendLine(value);
                this.int_0++;
            }
            if (stringBuilder.Length != 0)
            {
                action(stringBuilder, solidColorBrush);
                this.int_0++;
            }
            if (this.scrollViewer_0.ScrollableHeight.Equals(this.scrollViewer_0.ContentVerticalOffset))
            {
                this.scrollViewer_0.ScrollToEnd();
            }
        }
        finally
        {
            this.dispatcherTimer_0.Start();
        }
    }
  • 相关阅读:
    【JAVA笔记——道】JAVA对象销毁
    【JAVA笔记——道】并发编程CAS算法
    httpClientUtil的get请求
    python基础 day11 下 ORM介绍 sqlalchemy安装 sqlalchemy基本使用 多外键关联 多对多关系 表结构设计作业
    python基础 day11 上 数据库介绍 mysql 数据库安装使用 mysql管理 mysql 数据类型 常用mysql命令 事务 索引 python 操作mysql ORM sqlachemy学习
    Python基础 Day10 Gevent协程 SelectPollEpoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitMQ队列 RedisMemcached缓存 Paramiko SSH Twsited网络框架
    python基础 day9 进程、与线程区别 python GIL全局解释器锁 线程 进程
    python基础 day8 Socket语法及相关 SocketServer实现多并发
    python基础 day7 面向对象高级语法部分 异常处理 异常处理 Socket开发基础
    python基础 day6 面向对象的特性:封装、继承、多态 类、方法、
  • 原文地址:https://www.cnblogs.com/chucklu/p/11372019.html
Copyright © 2011-2022 走看看