Writing WCF messages to a text log in configurable directory
I have a WCF web service that is deployed at IIS. Part of the开发者_如何学Python web service is to validate the inputs using EntLib 4.1 For ex, the string values can be of specific length and so on. In case of the validation being failed a fault exception is raised and the service is supposed to write the message in log file.
How do I go about creating the log file to a location that can be configured from a config file. Basically how do we write messages from IIS (since the service is hosted at IIS, I am assuming that that will be the source!)
To write to the log file, make sure that the identity running your web application has write access to the log directory.
IIS7: You can find the identity in the IIS management console. Select the application pool that your web application is using. Click on Advanced Settings. In the properties window, look for the identity field. It may say Network Service. This is the account that needs write permission to your log output folder.
IIS6: Same as IIS7 except right click on the app pool and select properties. The properties window of IIS6 will have an Identity tab.
If you already have a log file in this directory, try deleting it and letting the framework create it.
Hope this helps.
Why not just write the warnings/error to the Event Log? It's easier to maintain than arbitrary log files and you can query them from other machines.
http://imar.spaanjaars.com/275/logging-errors-to-the-event-log-in-aspnet-applications
This website helped me with the same problem on IIS 7.5, where you have new Application Pool Identities: http://learn.iis.net/page.aspx/624/application-pool-identities/
Using the command line ICACLS test.txt /grant "IIS AppPool\<AppPoolName>":F on the log file or log folder worked for me.
Trying to set the permissions via the file/folder properties dialog failed, the AppPool identity was not accepted there.
精彩评论