How to log output to webservice launch from Visual Studio

Someone (not me) developed a website that hits a web service implemented in C #. When I run the website in visual studio, the project automatically starts the web service. In a web service, I want to write some information to a file for testing. log4net is used in the webservice project, but nothing is logged. I'll agree that I don't spend a lot of time working with log4net, but the hsa values ​​for the web.config that look like they should be creating a file, which they are not.

So, I tried to dump the text of interest for a text file on my local drive.

File.AppendAllText(logPath, txt + "\n");

      

No errors and nothing is sent to the file.

I'm running a Website, not a web service, so the debugger doesn't seem to know about the web service (so I can't just set a breakpoint on the web service).

My expectation is that for security reasons everything starts out in a way that it just prohibits. I vaguely remember that when started this way, your services were also not allowed to write to disk, so in a development window while running visual studio, how can I write a simple file to disk.

It seems to me that it should be simple.

+3


source to share


3 answers


First, you have to call the web service to register something. You can use an external program like fiddler or postman, or write a unit test. After the first call, you can attach visual studio to w3wp.exe so you can debug the problem.



The AppPool user must be granted write permission to the log file.

0


source


I want to comment on the above answer, but I have no rights.

To set a user write permission for the local development environment, just right click on the log folder, select properties, under the security tab, click Edit, add "EveryOne" with read, write, modify,



In a production environment, you must select a real user of the application instead.

0


source


While the answers were helpful and correct, this is not what solved the problem. Also, related, see this:

log4net does not generate log file when deployed to IIS7

Remember, I chose to start WebSite and automatically starts the WebService. This issue has NOT been resolved, but a colleague burned some brain cells and he thinks it has to do with how Visual Studio magically starts the web service and that log4net is NOT initializing. If I start the web service by itself, then the registration works as configured. I am still checking if the above advice can allow a lot to be written to a specific directory.

0


source







All Articles