项目1:
新建类MonitorHttpModule.cs


















































































<system.web>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="MonitorHttpModule" type="HouseProgram.HttpModule.MonitorHttpModule"/>
</httpModules>
</system.web>
项目2:
新建类MonitorClass.cs


public class MonitorClass : MarshalByRefObject
{
public MonitorClass()
{
//Console.WriteLine(String.Format("Client Constructor Called


}
~MonitorClass()
{
//Console.WriteLine(String.Format("Client Destructor Called


}
public delegate void RecordInfoHandler(string msg, string requestType);
public static event RecordInfoHandler OnRecordInfoEvent;
public void RecordInfo(string msg, string requestType)
{
if (OnRecordInfoEvent != null)
{
OnRecordInfoEvent(msg, requestType);
}
}
}
项目3:
新建Console 项目


namespace HouseProgram.RemotingServer
{
class Program
{
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8085);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MonitorClass), "HouseProgramMonitor", WellKnownObjectMode.SingleCall);
Console.BufferHeight = 30000;
MonitorClass.OnRecordInfoEvent += new MonitorClass.RecordInfoHandler(MonitorClass_OnRecordInfoEvent);
Console.WriteLine("Press Enter to exit.");
Console.ReadLine();
}
static void MonitorClass_OnRecordInfoEvent(string msg, string requestType)
{
switch (requestType)
{
case "POST":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(msg);
break;
case "GET":
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine(msg);
break;
default:
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(msg);
break;
}
}
}
}