www.pudn.com > Websharp2005.rar > Log.cs


using System;  
using System.Collections.Generic;  
using System.Text;  
using System.Runtime.Remoting.Messaging;  
using System.Diagnostics;  
  
namespace Websharp.Common  
{  
    public class Log  
    {  
        static Log()  
        {     
            if(!EventLog.SourceExists(Websharp))  
            {  
                EventLog.CreateEventSource(Websharp, Websharp);  
            }  
        }  
        public static void WriteLog(string msg)  
        {  
            EventLog log = new EventLog();  
            log.Source = Websharp;  
            log.WriteEntry(msg);  
            log.Close();  
            RegisterMessage(msg);  
        }  
  
        public static void RegisterMessage(string msg)  
        {  
            CallContext.SetData(LastMSG, msg);  
        }  
  
        public static string GetLastMessage()  
        {  
            string msg = CallContext.GetData(LastMSG) as string;  
            return (Object.Equals(null, msg) ? String.Empty : msg);  
        }  
  
        static string LastMSG = "LastMSG";  
        static string Websharp = "Websharp";  
    }  
}