Previous Next

Thread: need current log file name

Last post 09-13-2008 10:34 AM by devang123. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 09-04-2008, 7:05 AM

    need current log file name

    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.

  • 09-04-2008, 1:55 PM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 561

    Re: need current log file name

    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

  • 09-05-2008, 6:41 AM In reply to

    Re: need current log file name

    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.

  • 09-06-2008, 9:45 PM In reply to

    • marcoshaw
    • Not Ranked
    • Joined on 04-16-2008, 12:47 PM
    • Posts 9

    Re: need current log file name

    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

  • 09-13-2008, 10:34 AM In reply to

    Re: need current log file name

    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]

               }  

           }

       }

    }

Page 1 of 1 (5 items)
Page view counter