Skip to content

Instantly share code, notes, and snippets.

@ChocoSmith
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChocoSmith/0055a8ed92e57cf0e6a3 to your computer and use it in GitHub Desktop.
Save ChocoSmith/0055a8ed92e57cf0e6a3 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Web;
using NLog;
namespace Choco.Shared.Web.App_Start
{
public class LogSoapModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += this.OnBegin;
}
private void OnBegin(object sender, EventArgs e)
{
var context = ((HttpApplication) sender).Context;
var innerLogger = LogManager.GetLogger("incomingRequest");
innerLogger.Info(context.Request.Url);
if (!innerLogger.IsTraceEnabled)
return;
byte[] buffer = new byte[context.Request.InputStream.Length];
context.Request.InputStream.Read(buffer, 0, buffer.Length);
context.Request.InputStream.Position = 0;
string soapMessage = Encoding.ASCII.GetString(buffer);
if (!string.IsNullOrEmpty(soapMessage))
innerLogger.Trace(soapMessage);
}
public void Dispose()
{
//
}
}
}
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="LogSoapModule" type="Choco.Shared.Web.App_Start.LogSoapModule" />
</modules>
</system.webServer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment