WorldWind源码剖析系列:日志类Log

Utility工程中的日志类Log主要用来输出Debug状态下的调试信息。该类的类图如下:

 

日志类Log中使用到的类和内嵌结构体类型主要有以下这些:

public class LogEventArgs : EventArgs//日志事件参数

{

        public int level;

        public string category;

        public string message;

        public LogEventArgs(int _l, string _c, string _m)

        {

            level = _l;

            category = _c;

            message = _m;

        }

 }

        public struct Levels//调试日志等级

        {

            public static readonly int Error = 0;

            public static readonly int Warning = 2;

            public static readonly int Debug = 5;

            public static readonly int Verbose = 7;

        };

日志类Log中主要的字段、属性和方法有:

       static StreamWriter logWriter;//日志写盘的流式写入器

       static string logPath;//日志路径,默认为“C:\Documents and Settings\Administrator\Application Data\NASA\World Wind\1.4.0.0”

       static string logFilePath;//日志文件路径,为logPath+ “WorldWind.log”

public static int Level;//调试日志等级

其中的方法都很简单,不再详细赘述。只简单的说明其中三个常用的日志写出函数:

public static void Write( Exception caught )静态函数在程序中任何不活异常的地方被调用,用来将异常信息以“年月日时分秒.txt”为名称输出到文本文件中,默认的异常日志输出路径为“C:\Documents and Settings\Administrator\Application Data\NASA\World Wind\1.4.0.0”。

public static void DebugWrite( Exception caught ) 静态函数与public static void Write( Exception caught )静态函数功能一样,只不过是党程序处于Debug状态时才写出异常信息。

public static void Write(int level, string category, string message) 静态函数只将日志等级<= Log.Level(4或6)的日志写入到WorldWind.log文件中去。

下图是日志类Log在调试状态下向Output控制台输出日志信息的截屏。

 

posted @   rainbow70626  阅读(254)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示