以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 DTD/XML Schema 』  (http://bbs.xml.org.cn/list.asp?boardid=23)
----  can't log, please jim Answer  (http://bbs.xml.org.cn/dispbbs.asp?boardid=23&rootid=&id=54371)


--  作者:f1029303
--  发布时间:10/25/2007 7:57:00 PM

--  can't log, please jim Answer
Appcode/httphandler.cs

using System;
using System.IO;
using System.Text;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AppTalk.Util.Compression;
using AppTalk.Util.Configuration;
using AppTalk.Util.Log;
using AppTalk.Util.Delivery;
using AppTalk.Util.Messaging;


/// <summary>
/// Summary description for HttpHandler
/// </summary>
///
namespace AppTalk.Process.Http
{   

    public class HttpHandler : IHttpHandler
    {   
        private const string File_Name = @"../data/outbound/";       // for saving the raw data
        private const string CfgFile = @"../config/processSvc.cfg";  // for config file
        private string ReqStr = null;
        private string vStatusMsg = null;
       
        public void ProcessRequest(HttpContext ctx)
        {
            Logger.LogInfo("a new request start ...");
            try
            {
                Stream RcvStream = ctx.Request.InputStream;
                string ReqUrl = ctx.Request.Url.ToString();
                Logger.LogInfo("Url:" + ReqUrl);

                string CharSet = ctx.Request.Headers.Get("CharSet");
                Encoding Encode = System.Text.Encoding.GetEncoding(CharSet);
                StreamReader ReadStrm = new StreamReader(RcvStream, Encode);
                ReqStr = ReadStrm.ReadToEnd();
                byte[] RawData = System.Text.Encoding.UTF8.GetBytes(ReqStr);

                // if need GUnzip then ...
                string GzipFlg = ctx.Request.Headers.Get("Encoding");
                if (GzipFlg == "G-ZIP")
                {
                    RawData = GzipCompress.GUnZip(RawData);
                    Logger.LogInfo("Unzip successfully");
                }

                //get the config handle Type ( save to file  or  call application function)                     
                string MsgCatg = ctx.Request.Headers.Get("MsgCatg");
                string DocType = ctx.Request.Headers.Get("DocType");
                string DocID = ctx.Request.Headers.Get("DocID");
                string FileName = ctx.Request.Headers.Get("FileName");

                //get current folder
                string strCurrentPath = AppDomain.CurrentDomain.BaseDirectory + FileName;

                Logger.LogInfo("MsgCatg:" + MsgCatg + " " + "DocType:" + DocType + " " + "DocID:" + DocID + "" + "FileName:" + FileName);

                AppTalkMessage ATMsg = new AppTalkMessage();
                ATMsg.MsgCatg = MsgCatg;
                ATMsg.DocType = DocType;
                ATMsg.DocID = DocID;
                ATMsg.Encoding = GzipFlg;
                ATMsg.Charset = CharSet;
                ATMsg.FileName = strCurrentPath;
                ATMsg.Content = RawData;               

                MessageChannel MsgSender = new MessageChannel();
                string SendStatus = MsgSender.Send(ATMsg, out vStatusMsg);

            }
            catch (Exception ex)
            {
                Logger.LogInfo("Handle failed" + ex.ToString());
            }
        }


        public bool IsReusable
        {
            get
            {
                return true;
            }
        }


        public HttpHandler()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}

[此贴子已经被作者于2007-10-26 20:32:29编辑过]

--  作者:f1029303
--  发布时间:10/26/2007 8:35:00 PM

--  
// global.asax
// log4net.Config.XmlConfigurator.Configure();    Useful   ?????

<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        log4net.Config.XmlConfigurator.Configure();  // 2007-09-01

    }
    
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.

    }
       
</script>


--  作者:f1029303
--  发布时间:10/26/2007 8:40:00 PM

--  
// default.aspx.cs
// Logger.LogInfo(AppDomain.CurrentDomain.BaseDirectory+"test information");  can't log

//step 1
//C:\Inetpub\wwwroot\AppTalk\AppTalk.Http
//C:\Inetpub\wwwroot\AppTalk\AppTalk.Http\config  Log4net.cnf
//C:\Inetpub\wwwroot\AppTalk\AppTalk.Http\logs
    
// step 2
//C:\Inetpub\wwwroot\AppTalk\AppTalk.Http
//C:\Inetpub\wwwroot\AppTalk\config  Log4net.cnf
//C:\Inetpub\wwwroot\AppTalk\logs    

//Choose step 1 or  step 2


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AppTalk.Util.Log;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Logger.LogInfo(AppDomain.CurrentDomain.BaseDirectory+"test information");
        
        DateTime dt = DateTime.Now;
        Response.Write(dt+"</br>");
        Response.Write(AppDomain.CurrentDomain.BaseDirectory);
    }
}


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
70.313ms