Reputation: 11
With my custom OWIN middleware, I want to catch GET request to add a parameter to the query string.
I don't know if I'm correct, but actually I do it like this:
context.Request.QueryString = new QueryString(context.Request.QueryString.ToString() + "param=value")
But I also want that the IIS logging file entry for that request to be the updated request, not the original one.
Original log:
2015-07-22 09:32:35 ::1 GET /img.gif - 56782 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 200 0 0 102891
Expected log:
2015-07-22 09:32:35 ::1 GET /img.gif param=value 56782 - ::1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+Trident/7.0;+rv:11.0)+like+Gecko - 200 0 0 102891
How can I do that?
Upvotes: 1
Views: 329
Reputation: 396
For me the better option is create to own file log, not based on external logs (in this case IIS logs). For example you can use http://nlog-project.org/ and use it in your own OwinMiddleware.
public class GetMethodMiddleware : OwinMiddleware
{
public GetMethodMiddleware(OwinMiddleware next) :
base(next)
{ }
public override async Task Invoke(IOwinContext context)
{
var logger = ObjectFactoryHost.ObjectFactory.GetObject<ILogger>();
var requestMethod = (string)context.Request.Environment["owin.RequestMethod"];
var requestQueryString = (string)context.Request.Environment["owin.RequestQueryString"];
var requestPathString = (string)context.Request.Environment["owin.RequestPath"];
logger.Info(string.Format("{0}:{1}:{2}", requestMethod, requestQueryString,requestPathString));
await Next.Invoke(context);
}
}
and use it in startup configuration
app.Use(typeof(GetMethodMiddleware));
Upvotes: 0