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

本文介绍了Utility工程中的日志类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控制台输出日志信息的截屏。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值