IIS logging: don't write to log entry if match specific condition - iis

i'm looking for some way to avoid logging some specific files like
/WebResource.axd and /ScriptResource.axd
is there any way to write some code lines in Global.asa or add some configurations to do that?
thanks

No, logging happens inside of IIS and not in the ASP.Net layer.

Related

Wix installer. How to stop IIS pool

I faced with the problem in my WIX installer: how can I stop specific IIS application pool during repair, change or update?
Description: Deliver and deploy Web Application, run repair. Dialog appears that says that w3wp process locks files. In addition, because of requirements I cannot just hide that message and I cannot change Web Application.
What I tried to do:
I tried to stop service "W3SVC" with ServiceControl and it works excellent! But what I really need to do is to stop only one specific IIS pool.
I consider the way to write my own custom action to stop app pool, but as I know, I cannot schedule it before InstallValidate. Please, correct me if I'm wrong.
Please, help me overcome this issue.
You can use quiet execute custom action to shell out to appcmd to stop an app pool. You are right though, you wouldn't always be elevated prior to InstallValidate.
https://technet.microsoft.com/en-us/library/cc732742(v=ws.10).aspx
I suspect this is probably a false alarm and will resolve itself later in the installer. I would look at the various was to suppress this dialog. Maybe this would help:
WiX: Avoid showing files-in-use dialog and just prompt for reboot at end of install
First of all, please accept my great thanks!
As I understand, there are just two options to overcome the issue:
Add <ServiceControl Id="iisServiceControl" Name="W3SVC" Start="both" Stop="both" />, in case of you agree to stop the whole service
Add set property<Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable" Secure="yes"
/> and schedule your custom actions to stop/start your AppPool.
I guess to use options 2 due to the requirements. BUT, as I think, the best solution would be to say that after InstallValidate validator should just ignore some kind of processes filtering them by the name.

IIS 7.5 AutoStart Feature doesn't work

I am new to IIS 7.5, and I'm trying to use the AutoStart feature, as described in ScottGu's blog and MSDN.
I implemented my own Preload() in my own IProcessHostPreloadClient and I just print to the log and event viewer there.
But it seems I never reach the Preload(), since nothing is being printed. I expect to see the prints when I restart the Application Pool, but, as I said, nothing is happening.
Any suggestions as to what he problem could be? Or how can I check the reason for the problem?
I just print to the log and event viewer there
That could be your problem. Are you sure you can write to the event log at all from within your web app? Traditionally you won't have enough permission to do it in an asp.net app hosted in IIS running the standard permissions.
Try putting a test page in your web app that writes to the event log to make sure your print to event log code is working. If it's not, can you go the simple option of writing a text file to your app_data folder? You've normally got enough permission to write to it.

IIS: Where can I find the IIS logs?

I'm trying to set up an application from a third party, which requires a supporting website hosted in my local IIS. I've created a website exactly as explained in their install guide, but am having some problems, and would like to see what the IIS log has to say. Embarrassingly enough, the problem is I can't find the log files!
So my question is: Where does IIS7 store logs by default?
I think the default place for access logs is
%SystemDrive%\inetpub\logs\LogFiles
Otherwise, check under IIS Manager, select the computer on the left pane, and in the middle pane, go under "Logging" in the IIS area. There you will se the default location for all sites (this is however overridable on all sites)
You could also look into
%SystemDrive%\Windows\System32\LogFiles\HTTPERR
Which will contain similar log files that only represents errors.
I believe this is an easier way of knowing where your IIS logs are, rather than just assuming a default location:
Go to your IIS site, e.g. Default, click on it, and you should see "Logging" to the right if logging is enabled:
Open it and you should see the folder right there:
You are welcome!
I'm adding this answer because after researching the web, I ended up at this answer but still didn't know which subfolder of the IIS logs folder to look in.
If your server has multiple websites, you will need to know the IIS ID for the site. An easy way to get this in IIS is to simply click on the Sites folder in the left panel. The ID for each site is shown in the right panel.
Once you know the ID, let's call it n, the corresponding logs are in the W3SVCn subfolder of the IIS logs folder. So, if your website ID is 4, say, and the IIS logs are in the default location, then the logs are in this folder:
%SystemDrive%\inetpub\logs\LogFiles\W3SVC4
Acknowlegements:
Answer by #jishi tells where the logs are by default.
Answer by #Rafid explains how to find actual location (maybe not default).
Answer by #Bergius gives a programmatic way to find the log folder location for a specific website, taking ID into account, without using IIS.
The 100% correct answer for the default location of the log files is...
%SystemDrive%\inetpub\logs\LogFiles
Yes you can enter this into the explorer address bar it'll work.
To be 100% sure, you need to look at the logging for the web site in IIS.
https://learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-85/enhanced-logging-for-iis85
i.e.
Open IIS Manager.
Select the site or server in the Connections pane,
Double-click Logging.
The location of log files for the site can be found within the Directory field
EDIT: As pointed out by Andy in the comments below you need to ensure when installing IIS that you elected to enable HTTP logging, otherwise HTTP logging won't be available.
A much easier way to do this is using PowerShell, like so:
Get-Website yoursite | % { Join-Path ($_.logFile.Directory -replace '%SystemDrive%', $env:SystemDrive) "W3SVC$($_.id)" }
or simply
Get-Website yoursite | % { $_.logFile.Directory, $_.id }
if you just need the info for yourself and don't mind parsing the result in your brain :).
For bonus points, append | ii to the first command to open in Explorer, or | gci to list the contents of the folder.
Try the Windows event log, there can be some useful information
Enabling Tracing may be a better alternative to the Windows Event Log. This gave me the information I needed to fix my own WebService.
I think the Default place for IIS logging is: c:\inetpub\wwwroot\log\w3svc
I have found the IIS Log files at the following location.
C:\inetpub\logs\LogFiles\
which help to fix my issue.
C:\inetpub\logs\LogFiles
Check the identity of the site going to sites and advanced settings
The simplest answer is to query like this:
(Get-Website * | % { $_.logFile.Directory});ls $GetIISLogs\W3SVC1\*
If you have more than one site you will get more than one answer, so you need to query with a 'foreach' to get the website name with the directory...

Add HttpHandler registration in web.config in runtime

I was trying to add some configuration in web.config file after the web page is started up. Such as:
But when I deploy it to the IIS, there of course has an authority issue to modify the web.config file. So I need add everyone permission to this application in IIS.
My question is: could any one give me a clue that I can add this configuration in runtime without the everyone permission? Such as adding this configuration to memory?
Thanks,
I just have a workaround to register the httphandler to web.config in the OnPreRender life-circle and it works fine; but the bad thing is that when we deploy it, we need give it a higher privilege. If you have better idea, please share it.

How to switch on/off logging using Log4net

I have logged all my applications transaction using Log4net. Is there any way I can disable and enable logging from a common place without altering the code written for logging.
I assume you want to toggle logging in your running application through code. I did not try it but I think that calling the following method should disable logging:
LogManager.GetRepository().ResetConfiguration();
To re-enable logging you would call
XmlConfigurator.Configure();
(or one of the other methods of the XmlConfigurator).
However there seems to be an issue with calling the Configure method repeatedly. I do not know if this would be a problem for you, but at least I warned you...
You can turn them off by changing the log4net config file. Specifically change the appender's level or global level to "OFF" value. See here for details
Assuming I understand your question, from the FAQ: http://logging.apache.org/log4net/release/faq.html
How do I completely disable all logging at runtime?
Setting the Threshold on the Hierarchy to Level OFF will disable all logging from that Hierarchy. This can be done in the log4net configuration file by setting the "threshold" attribute on the log4net configuration element to "OFF". For example:

Resources