Boone
Boone

Reputation: 1056

Add username to my weblogs for .net

I would like the weblogs that asp.net/IIS7 uses to have the customer's username and some unique Id's in each request. What would be the best way to accomplish this or is there a better tool than IIS7's logging?

On each line in the log, I would like to see the IP, username, userID, datetime, and what page they were viewing. I also want to make sure the user can not see these ID's in the page header.

If I use C# to append to log. How big of performance hit am I going to take with every page hit?

Also I am using forms authentication if that is any help. Thanks in advance.

Upvotes: 0

Views: 709

Answers (3)

Stuart
Stuart

Reputation: 66882

If you're using standard IIS7 logging and your app uses forms based authentication then username can be included in the W3C log files. In the IIS management UI choose "Logging", make sure format is W3C, then in "select fields" make sure that the User Name ("cs-username") field is checked.

To study the produced log files, try the logparser tool - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=24659 - this can help you remove e.g. all the image and css files that get requested

Some example file output is http://technet.microsoft.com/en-us/library/cc738725(WS.10).aspx

How to select the fields for the log files - http://technet.microsoft.com/en-us/library/cc754702(WS.10).aspx

Upvotes: 1

Sascha
Sascha

Reputation: 10347

I think IIS logs aren't the right place for application specific log entries like userids. I would opt for a custom logging - users somewhere need to login, therefore the values you want aren't alway available. What I have done is to create a click path log, that logs a timestamp, the URL, a userid and the session in each page load that is a full page load. I've done this using Enterprise Library as I felt this is very comfortable and fast ( have I mentioned configurable? ). With the session id you're also able to connect IIS logs to your custom logs

Upvotes: 1

coder net
coder net

Reputation: 3475

You can write a custom health monitoring provider and add it to the health monitoring section. You can have this go to a database or a flat file.

Take a look at this video. You can then create a base page and trigger this custom event supplying all the information you need at the time you write to the file, on every page load.

Upvotes: 0

Related Questions