Question

I have created a Windows service to open the IIS log, read content, then e-mail this content to consultants that 'The Man' doesn't want to have any access to those servers. On my local machine, everything works great, and the file generated from parsing the IIS log for the day is e-mailed to the recipients.

I do not have access to install my service on the development system. I had the administrator install the service. The service has LocalSystem permissions. When the service runs, I receive this message in the Application log:

LogExtractor: GetIISLog function - C:\WINDOWS\system32\LogFiles\W3SVC1\ex090918.log does not exist.

The administrator has confirmed that the path is correct, and the file does exist. (My user account does not have access to the W3SVC1 directory.) It was my understanding that the System account is the uber-account, and can do pretty much what it wants, so I'm at a loss as to why it cannot read the file. I'm assuming it's a permissions issue, since the files does exist.

Here is the relevant code. I've snipped the logic involved in the section about reading the file. The code works, as it runs successfully on one system, but not another, so I know the path is being generated correctly. Any ideas?

Private Sub GetIISLog(ByVal LastRetrievedDate As DateTime)

    'Build the file path to store the IIS event log before sending it off (previous code snipped)
    Dim FileDate As String = "ex" & Date.Now.Year.ToString.Substring(2, 2) & Month & Day & ".log"
    Dim FileName As String = "C:\WINDOWS\system32\LogFiles\W3SVC1\" & FileDate

    'If the file doesn't exist, exit
    If Not File.Exists(FileName) Then
        LogIssues("LogExtractor: GetIISLog function - " & FileName & " does not exist.", EventLogEntryType.Error)
        Exit Sub
    End If

    Dim s As Stream = Nothing

    Try
        s = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
        Dim strResult As String = String.Empty

        Using sr As New StreamReader(s)
            Using sw As New StreamWriter(IISLogFile, False)

                strResult = sr.ReadLine

                While Not strResult Is Nothing

                    sw.WriteLine(strResult)

                    'Write the results
                    strResult = sr.ReadLine

                End While
            End Using

            sr.Close()
        End Using

        s.Close()
    Catch ex As Exception
        LogIssues("LogExtractor: Error writing IIS file - " & ex.Message, EventLogEntryType.Error)
    Finally
        s.Close()
    End Try

    s = Nothing

End Sub
Was it helpful?

Solution 2

I figured out the issue. IIS had been configured to log to a database, so the files I was looking for didn't exist. Unfortunately, I have access to neither the W3SVC1 folder nor to IIS, so I never knew that. I suppose when I asked the administrator the question "Is ex090920.log the corrrect format?", I should have asked if the file existed at all.

Well, at least it's solved, with (hopefully) no permanent damage because of all the head-banging.

Thanks for your suggestions Stephen and ongle.

OTHER TIPS

If the server is running a 64 bit OS then the most likely reason for this is that your two processes, IIS and your log processing service, are running with different bitness.

On a 64 bit machine file system redirection causes 32 bit processes accessing system32 to actually access SysWOW64. So if one of your processes is running as a 64 bit process and the other as a 32 bit process they will actually be accessing two different locations when they read from or write to system32.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top