3

I'm trying to find a way to log the regex that was used to the match a route from MVC3 (i.e. /api/person/{personid}/address/{addressid})

I've found that you can use HttpResponse.AppendToLog in order to append something onto the cs-uri-query in the IIS logs, but this is pretty hacky and makes processing the logs a pita.This has led me to HttpModules and IIS7 Advanced logging.

My current understanding is that I can make fields available to Advanced Logging from an HttpModule. So I should be able to look up the regex used by the Route object in the HttpContext and expose that as a field that Advanced Logging can consume and log.

My issue is that I'm having issues figuring out exactly how to expose data as a field in a custom HttpModule that Advanced Logging can consume.

Do I need to have an event handler for LogRequest? If I do that what am I supposed to do in the event handler to make it consumable for Advanced Logging?

Any pointers, code samples and/or links to documentation would be greatly appreciated.

As an aside if you know of any documentation explaining/listing the available 'published' fields from default modules installed in IIS7 I'd appreciate a link.

1 Answer 1

2

OK, the way that I end up dealing with this is to create a HttpModule that will pull the route pattern from the HttpContext and put into the server variables as URL_PATTERN.

Once its in server_variables IIS7 Advanced Logging can get ahold of it and save it. If the current request doesn't have a route it'll just use the normal local portion of the url (so it'll match cs-uri-stem in the logs).

Now sql / log parser the query:

select url_pattern,count(url_pattern) from (yourlogs) where timestamp between (start/end) group by url_pattern order by count(url_pattern) desc

will give me back the number of hits for each endpoint in my app.

This could obviously be done in fubu a behaviour, but we've got a bunch of classic asp and MVC3 running around (i know I know...) and this will handle all of them.

Also you can apparently 'publish' a field from a module using RaiseTraceEvent that IIS7 Advanced Logging can then get ahold of, but it was giving me fits trying to figure it out so I just went with what I have.

I've posted this question all over the place referencing fubu and MVC3 and I have gotten little to no interest, which really suprised me. How do people poke about in their logs for info if you can't easily determine the routes being used.

https://gist.github.com/2854760

I'll just leave this here.... There are still several unanwsered parts to this so I'll leave this post, but not mark it an anwser.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.