I've asked a question regarding creating an IIS logger, but am still having a couple of issues:
- Original message is lost
- Response message is not captured
Would it be at all possible to get these 2 sorted out?
IHttpHandler:
using System.Web;
using System.IO;
namespace MyLogger
{
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.Write("The page request is " + context.Request.RawUrl.ToString());
StreamWriter sw = new StreamWriter(@"C:\requestLog.txt", true);
sw.WriteLine("Page requested at " + DateTime.Now.ToString() + context.Request.RawUrl);
sw.Close();
}
public bool IsReusable
{
get
{
return true;
}
}
}
}
IHttpModule:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
namespace MyLogger
{
public class MyModule : IHttpModule
{
public InterceptorModule()
{ }
public void Init(HttpApplication objApplication)
{
// Register event handler of the pipe line
objApplication.BeginRequest += new EventHandler(this.ContextBeginRequest);
objApplication.EndRequest += new EventHandler(this.ContextEndRequest);
}
public void Dispose()
{
}
public void ContextEndRequest(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(@"C:\requestLog.txt", true);
sw.WriteLine("End Request called at " + DateTime.Now.ToString()); sw.Close();
}
public void ContextBeginRequest(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(@"C:\requestLog.txt", true);
sw.WriteLine("Begin request called at " + DateTime.Now.ToString()); sw.Close();
}
}
}
My previous post: IIS API Monitor in a web application Thanks in advance!