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 @ 2015-06-07 21:46  rainbow70626  阅读(254)  评论(0编辑  收藏  举报