PageRenderTime 28ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/projects/PigeonCms.Core/Helpers/Trace.cs

http://pigeoncms.googlecode.com/
C# | 102 lines | 92 code | 6 blank | 4 comment | 6 complexity | f420f5779b3a5e54208759f0e5d51da9 MD5 | raw file
  1using System;
  2using System.Web;
  3
  4namespace PigeonCms
  5{
  6    /// <summary>
  7    /// encapsulate trace functionality, avoid trace exception and time loss when tracing is disabled
  8    /// tnx to http://weblogs.asp.net/plip/articles/111130.aspx
  9    /// </summary>
 10    public class Trace
 11    {
 12        public static void Write(string Message)
 13        {
 14            if (HttpContext.Current.Trace.IsEnabled)
 15            {
 16                try
 17                {
 18                    HttpContext.Current.Trace.Write(Message.ToString());
 19                }
 20                catch (Exception e)
 21                {
 22                    HttpContext.Current.Trace.Warn("PigeonCms", "Trace.Write", e);
 23                }
 24            }
 25        }
 26
 27        public static void Write(string Category, string Message)
 28        {
 29            if (HttpContext.Current.Trace.IsEnabled)
 30            {
 31                try
 32                {
 33                    HttpContext.Current.Trace.Write(Category.ToString(), Message.ToString());
 34                }
 35                catch (Exception e)
 36                {
 37                    HttpContext.Current.Trace.Warn("PigeonCms", "Trace.Write", e);
 38                }
 39            }
 40        }
 41
 42        public static void Write(string Category, string Message, System.Exception exe)
 43        {
 44            if (HttpContext.Current.Trace.IsEnabled)
 45            {
 46                try
 47                {
 48                    HttpContext.Current.Trace.Write(Category.ToString(), Message.ToString(), exe);
 49                }
 50                catch (Exception e)
 51                {
 52                    HttpContext.Current.Trace.Warn("PigeonCms", "Trace.Write", e);
 53                }
 54            }
 55        }
 56
 57        public static void Warn(string Message)
 58        {
 59            if (HttpContext.Current.Trace.IsEnabled)
 60            {
 61                try
 62                {
 63                    HttpContext.Current.Trace.Warn(Message.ToString());
 64                }
 65                catch (Exception e)
 66                {
 67                    HttpContext.Current.Trace.Warn("PigeonCms", "Trace.Warn", e);
 68                }
 69            }
 70        }
 71
 72        public static void Warn(string Category, string Message)
 73        {
 74            if (HttpContext.Current.Trace.IsEnabled)
 75            {
 76                try
 77                {
 78                    HttpContext.Current.Trace.Warn(Category.ToString(), Message.ToString());
 79                }
 80                catch (Exception e)
 81                {
 82                    HttpContext.Current.Trace.Warn("PigeonCms", "Trace.Warn", e);
 83                }
 84            }
 85        }
 86
 87        public static void Warn(string Category, string Message, System.Exception exe)
 88        {
 89            if (HttpContext.Current.Trace.IsEnabled)
 90            {
 91                try
 92                {
 93                    HttpContext.Current.Trace.Warn(Category.ToString(), Message.ToString(), exe);
 94                }
 95                catch (Exception e)
 96                {
 97                    HttpContext.Current.Trace.Warn("PigeonCms", "Trace.Warn", e);
 98                }
 99            }
100        }
101    }
102}