IIS 7 Logging Web Service methods
I have a web service (not a WCF service) hosted under IIS 7, the web service has two methods: method1, and method2.
I am looking to differentiate between the requests for method1, versus the requests for method2, without modifying the web service code.
Under the IIS 7 logs, I can see the requests to the web service, the web service URL gets logged under the "cs-uri-stem" field, but the "cs-uri-query" field is empty.
Is there anyway to log the requests for the web service methods, without modifying the web service code?
You can log all incoming request inside various methods of the processing pipeline. For example, add a handler for BeginRequest
in your Global.asax
:
Application_BeginRequest( object sender, EventArgs e )
{
HttpApplication app = (HttpApplication)sender;
HttpContext ctx = app.Context;
var requestUrl = ctx.Request.Url;
// the uri should be of a form:
// http://yoursite/theservice.asmx/MethodName
}
Years later, I've had to visit an ASMX with hundreds of methods and it's just not possible to convert to WCF. Here is an ASMX extension point that allows you to log the method name without visiting all methods. Here, I'm using log4net to log the method name, YMMV
First, create a SoapExtension class:
namespace MyNamespace {
public class WebMethodLogger : SoapExtension
{
private static readonly ILog _log = LogManager.GetLogger(typeof(WebMethodLogger));
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
return null; //No state
}
public override object GetInitializer(Type serviceType)
{
return null; //No state
}
public override void Initialize(object initializer)
{
//Do nothing
}
public override void ProcessMessage(SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterDeserialize)
_log.Debug(message.MethodInfo.MethodInfo.Name);
}
}
}
Then, register the extension in your web.config:
<system.web>
...
<webServices>
<soapExtensionTypes>
<add type="MyNamespace.WebMethodLogger, MyAssembly"
priority="1"
group="High" />
</soapExtensionTypes>
</webServices>
...
</system.web>
Here is the oficial article from microsoft: http://support.microsoft.com/kb/313437
1- Start Internet Information Services (IIS) Manager.
2- Expand ServerName, and then expand Web Sites or FTP Sites. Right-click the Web site or the FTP site where you want to enable logging, and then click Properties.
3- Click the Web Site tab, or click the FTP Site tab.
4- Click to select the Enable logging check box.
5- In the Active log format box, click the format that you want to use.
6- Click Properties, and then specify the settings that you want. For example, if you use W3C Extended log file format, follow these steps:
a. If you are running IIS 6.0, click the General tab. If you are running IIS 5.0 or IIS 4.0, click the General Properties tab. Specify the schedule that you want to use to create new log files. For example, to create a new log file every day, click Daily.
b. If you want to use local time, click to select the Use local time for file naming and rollover check box.
Note Midnight local time is used for all log file formats except W3C Extended log file format. By default, W3C Extended log file format uses midnight Coordinated Universal Time (Greenwich Mean Time). To use midnight local time, click to select the Use local time for file naming and rollover check box.
c. If you are running IIS 6.0, click the Advanced tab. If you are running IIS 5.0 or IIS 4.0, click the Extended Properties tab.
d. Specify the options that you want. For example, specify the properties that are listed in the "Customize the data" section. Click OK.
e. Click OK.
链接地址: http://www.djcxy.com/p/10364.html上一篇: MVC3不发布整个模型
下一篇: IIS 7记录Web服务方法