need current log file nameRSS

4 replies

Last post Sep 13, 2008 10:34 AM by devang123

  • need current log file name

    Sep 04, 2008 07:05 AM|devang123|LINK

    Hi,

    I am trying to write a powershell function which is conceptually quite simple but I am having a hard time getting the right information. Maybe the experts can help.

    What I want, essentially, is the current path of the logfile for a particular site. e.g. if my site is named "devang", I want to write a function called "show-log devang" which should "tail" the logfile for the site "devang" (assume that I have the logging configured to have a separate file at the site level).

    Why is this hard? Well, it looks like in IIS, a directory like "w3csvc1" is created in the standard logs directory. The mapping from "devang" to "w3svc1" is known to IIS but is not obvious otherwise. In addition, IIS rotates the log (daily, weekly, etc.) and so the current file name is not stable.

    IIS has to know what file it is writing the log to...so, how do I query IIS to get the full path name?

    Hope someone can help?

    Thanks.

  • Re: need current log file name

    Sep 04, 2008 01:55 PM|ksingla|LINK

    Hi devang123,

    Mapping from website name "devang" to w3svc1 is pretty simple. All you need to do is get the site id of website and the logs get created in %systemdrive%\inetpub\logs\logfiles\w3svc<siteId>. If you want the current log file which is getting written, you can pick the file which has the 'last modified time' closest to current time.

    Thanks,
    Kanwal

  • Re: need current log file name

    Sep 05, 2008 06:41 AM|devang123|LINK

    Thanks Kanwal. I was trying to avoid checking for mod times originally. Anyway, I got it working with your suggestion.

    I hope that folks at MSFT who are watching will hopefully add a simple way to do this in the future.

  • Re: need current log file name

    Sep 06, 2008 09:45 PM|marcoshaw|LINK

    I haven't check out IIS7, but if I remember correctly, older versions had the current active log file in a different temporary directory before being moved to their more permanent location.

    How were you planning to implement tail in PowerShell?  It appears there's a tail.exe with one of the recent enough MS Resource Kits.

    Marco
    Windows Server - Admin Frameworks MVP

  • Re: need current log file name

    Sep 13, 2008 10:34 AM|devang123|LINK

    I don't have the latest powershell 2.0. Is tail.exe in 2.0? I implemented a rudimentary tail function in my $profile . Here is the code:

     function tail([string] $filename) {

       $a = Get-Content $filename
       $length = $a.length

       $i = $length - 10

       if ($i -lt 10) { $i = 0 }

       for ( ; $i -lt $length; ++$i ) {

          $a[$i]

       }

       while(1) {

           start-sleep -s 1
          
           $a = Get-Content $filename

           if ($length -lt $a.length) {
      
        for ( ; $length -lt $a.length; ++$length) {

                  $a[$length]

               }  

           }

       }

    }