Writing to a registered source in the Application event log with I

G

Guest

Writing to a registered source in the Application event log

I have an asp.net framework 2.0 app that I created on a winxp machine and
now I am deploying it to IIS6 on a win server2003 machine. This application
has to write to the application event log.

After deployment of the application I have verified that my source
“MySource†exists in the Application event log. I then wrote some text to
the event source in a forms app and verified that it showed up in the
Application event log.

Since I don’t require my Application to create the event log source I don’t
believe I should have to give Network Service additional rights. I have
spent the day reading posts about writing to the event log to no avail.

Thanks in advance

-Jeff


My application throws this exception when it hits the line requiring it to
write to the event log :

Access to the path 'C:\Documents and Settings\Default User\Application
Data\Microsoft Corporation\Internet Information Services\6.0.3790.1830' is
denied.

//--------- Writing to the event log

My.Log.WriteEntry(“Success I have written to the event logâ€)


// ----------- Excerpt from my webConfig file ----------------

<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for
My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event
Log -->
<add name="EventLog"/>
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information"/>
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME (now
'default') with the name of your application to write to the Application
Event Log -->
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="MySource"/>
</sharedListeners>
</system.diagnostics>
 
W

Walter Wang [MSFT]

Hi Jeff,

Thank you for your post.

Based on my understanding, you're having problem writing log in ASP.NET and
IIS 6.0.

After reviewed your web.config and the source code, I've been able to
reproduce the problem on my test environment. I also found that the problem
is not related to the event log part, you're doing right that create the
event source first. The problem is actually related to the FileLog part.

FileLogTraceListener.Location default to LocalUserApplicationDirectory.

You can change it to Custom and use the CustomLocation property to specify
the log file location. Just make sure you give the NETWORK SERVICE account
required ACL to the location.

<add name="FileLogListener"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
initializeData="FileLogListenerWriter"
location="Custom"
customlocation="c:\temp\" />

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Walter thanks for your response!

I am still unable to get this to work.

I notice that this custom log writes to a file. Does this mean having the
network service account write to the application log is not recommended? I
would like my log to be visible from the Computer Management Snap-in.

From you advice and 2 msdn articles:
http://msdn2.microsoft.com/en-us/library/yhx0xwks.aspx
http://msdn2.microsoft.com/en-us/library/5cz98azz.aspx

This is the new version of the web.config file excerpt

<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for
My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>

<!-- Uncomment the below section to write to the Application Event Log -->
<!—
If writing to the event log is causing the problem I don’t believe we want
this listener to receive log messages anymore.

<add name="EventLog"/>
-->
<add name="FileLogListener" />
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information"/>
</switches>
<sharedListeners>

<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME (now
'APPLICATION_NAME') with the name of your application to write to the
Application Event Log -->

<!--
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener"
initializeData="MySource"/>
-->

<add name="FileLogListener"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" initializeData="FileLogListenerWriter"
location="Custom" customlocation="C:\LogFiles\" />

</sharedListeners>
</system.diagnostics>

On my laptop running XP

My.Log.WriteEntry("Testing")

Creates a log file (“WebDev.WebServer.log “) in the correct location
(“C:\LogFiles\â€) as expected however the log file remains empty without any
exceptions being thrown. So none of the messages are being recorded.


On the Win2003 Server

I still get the same error message:

"Access to the path 'C:\Documents and Settings\Default User\Application
Data\Microsoft Corporation\Internet Information Services\6.0.3790.1830' is
denied."

Note: I have given “Network Service†Full Control of “C:\LogFiles\â€

And on the XP machine my web.config provided the correct information to
create the “WebDev.WebServer.logâ€.

I don’t know what is causing it to look in that folder. I have also tried
commenting out the FileLog listner entry ( <add name="FileLog"/> ) and the
sharedListner entry (
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
) and I still get the same error.

Where you able to get this to work? Could you send me your webconfig file?


Thanks,

Jeff
 
W

Walter Wang [MSFT]

Hi Jeff,

Thank you for your update.

I'm sorry that I didn't fully test the code in my last mail. I've now been
able to reproduce the issue you've described and found that it's a known
issue of FileLogTraceListener.

#Issues When Using Microsoft Visual Studio 2005
http://msdn.microsoft.com/vstudio/support/knownissues/default.aspx
Search for section 1.43 "My.Application.Log.WriteEntry may throw an
exception if user does not have File I/O permission".

I'm sorry for the inconvenience of this issue.

Since you mentioned that you want to your log to be visible from the
Computer Management snap-in, I suppose you're referring to the Event Log
viewer in Computer Management snap-in. You only need the EventLog listener
to do that.

Hope this helps. Please feel free to post here if anything is unclear.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Jeff,

I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.

Have a great day!

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

cory

I haven't seen a good answer to this question, and this solution
probably isn't a good workaround, but it worked for me. If someone has
the fix please post.

After a blunder of instantiating
Microsoft.VisualBasic.Logging.FileLogTraceListener and trying to work
with that, I noticed a recurring error about access denied to a certain
path.

What finally seemed to work for me was to create the following
directory structure where C is the drive where the user profiles are
stored.

C:\Documents and Settings\Default User\Application Data\Microsoft
Corporation\Internet Information Services\6.0.3790.1830

Then on my page, I assure the log file writer points to my custom log
....

With My.Log.DefaultFileLogWriter
.Append = True
.AutoFlush = True
.BaseFileName = "MyApp"
.CustomLocation = "C:\Examples\MyApp\Logs"
.Location = Logging.LogFileLocation.Custom
.LogFileCreationSchedule =
Logging.LogFileCreationScheduleOption.Daily
End With

Then I write

My.Log.WriteEntry(Now.ToString + ": " + msg + vbCrLf)
 
G

Guest

Walter,

Sorry for the delay in getting back to you. I've been on vacation.

All I had to do was comment out the <add name="FileLog"/>
This was what kept throwing the exception. Its placement in the webcofig
file made me think it was necceary to do any logging. However it is not
necessary to write to the event log.

I tried the logging to file but wasn't able to get it to work consistently.
But this was not my original goal.

Thanks,

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top