locked
need current log file name RRS feed

  • Question

  • User-2129664311 posted

    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.

    Thursday, September 4, 2008 7:05 AM

All replies

  • User-1653247517 posted

    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

    Thursday, September 4, 2008 1:55 PM
  • User-2129664311 posted

    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.

    Friday, September 5, 2008 6:41 AM
  • User2065605267 posted

    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

    Saturday, September 6, 2008 9:45 PM
  • User-2129664311 posted

    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]

               }  

           }

       }

    }

    Saturday, September 13, 2008 10:34 AM