Skip to content

"Unknown directive" and "No folders found in section(s)" #60

@celorodovalho

Description

@celorodovalho

I have this config:

"C:\inetpub\wwwroot\shared\var\log\*.log" {
	daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    dateext
    dateformat .%Y-%m-%d
    copytruncate
    sharedscripts
	prerotate
        powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "New-Item -ItemType Directory -Force -Path 'C:\inetpub\wwwroot\archive' | Out-Null"
    endscript
    postrotate
        powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\logrotate\Content\postrotate.ps1
    endscript
    olddir "C:\inetpub\wwwroot\archive"
}

postrotate.ps1

# Save as: C:\logrotate\postrotate.ps1
$ErrorActionPreference = 'Stop'

$archive = 'C:\inetpub\wwwroot\archive'
$logDir  = 'C:\inetpub\wwwroot\shared\var\log'

New-Item -ItemType Directory -Force -Path $archive | Out-Null

# gzip any rotated logs in archive that aren't already .gz
Get-ChildItem -Path $archive -File -Filter '*.log.*' |
  Where-Object { $_.Name -notlike '*.gz' } |
  ForEach-Object {
    # Requires gzip in PATH (e.g., Git for Windows, Cygwin, etc.)
    & gzip -9 $_.FullName
  }

$today = (Get-Date).ToString('yyyy-MM-dd')

# remove dated log files from shared log dir except "today"
Get-ChildItem -Path $logDir -File |
  Where-Object { $_.Name -match '.*-\d{4}-\d{2}-\d{2}\.log$' } |
  ForEach-Object {
    $m = [regex]::Match($_.Name, '\d{4}-\d{2}-\d{2}')
    if ($m.Success -and $m.Value -ne $today) {
      Remove-Item -Force $_.FullName
    }
  }

logrotate-scheduled.ps1

$logFile = "C:\logrotate\logrotate-task.log"
$configFile = "C:\logrotate\Content\logrotate.conf"

"[$(Get-Date)] Starting log rotation..." | Out-File $logFile -Append

& logrotate -v $configFile

$exitCode = $LASTEXITCODE
"[$(Get-Date)] Exit code: $exitCode" | Out-File $logFile -Append

# Only fail the task for actual errors (not for "no files to rotate")
if ($exitCode -gt 0 -and $exitCode -ne 4) {
    "[$(Get-Date)] ERROR: Log rotation failed" | Out-File $logFile -Append
    exit $exitCode
}

"[$(Get-Date)] Log rotation completed" | Out-File $logFile -Append
exit 0

But when I try to run .\logrotate-scheduled.ps1
I got this error:

PS C:\logrotate> .\logrotate-scheduled.ps1
logrotate: Verbose option set to true
logrotate [VRB]: C:\logrotate\Content\logrotate.conf Adding to config files to process
logrotate [VRB]: Status file located in C:\logrotate\logrotate.status
logrotate [VRB]: Parsing configuration file C:\logrotate\Content\logrotate.conf
logrotate [VRB]: Processing new section
logrotate [WRN]: Unknown directive "C:\inetpub\wwwroot\shared\var\log\*.log" {
logrotate [ERR]: No folders found in section(s)

dir C:\inetpub\wwwroot\shared\var\log\ gives me:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       22.01.2026     18:00     8771525678 prod.log

What I'm missing here?

Version 0.0.28

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions