chocolatey / choco

Chocolatey - the package manager for Windows
https://chocolatey.org
Other
10.05k stars 890 forks source link

Log cannot rotate when Chocolatey CLI is run by non-admin #3407

Open pauby opened 3 months ago

pauby commented 3 months ago

Checklist

What You Are Seeing?

When the Chocolatey logs reach their configured rotation size, non-admin users will receive a log4net error message: log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\ProgramData\chocolatey\logs\chocolatey.log] already exists.

What is Expected?

Log file rotation to happen.

How Did You Get This To Happen?

  1. Install Chocolatey.
  2. Fill up the chocolatey.log and choco.summary.log files.
    $chocolatey = [System.IO.FileStream]::new('C:\ProgramData\chocolatey\logs\chocolatey.log',[System.IO.FileMode]::Append)
    $chocolatey.Seek(15MB, [System.IO.SeekOrigin]::Begin)
    $chocolatey.WriteByte(0)
    $chocolatey.Close()
    $chocolatey = [System.IO.FileStream]::new('C:\ProgramData\chocolatey\logs\choco.summary.log',[System.IO.FileMode]::Append)
    $chocolatey.Seek(15MB, [System.IO.SeekOrigin]::Begin)
    $chocolatey.WriteByte(0)
    $chocolatey.Close()
  3. From a non-administrator session run choco list | Out-Null (The Out-Null is to drop the standard output stream as it's not necessary for this.)
  4. Check the log files sizes (ls c:\programdata\chocolatey\logs) to see they're about 15 MB
  5. Receive message on standard error:
    log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\ProgramData\chocolatey\logs\chocolatey.log] already exists.
    log4net:ERROR RollingFileAppender: INTERNAL ERROR. Append is False but OutputFile [C:\ProgramData\chocolatey\logs\choco.summary.log] already exists.
  6. Check the log file sizes again to see that they are now much less (my test system were 388 and 12,202 bytes)
  7. Repeat steps 2 - 6 from an Administrator terminal. You should not receive the log4net error message, and should now have a choco.summary.1.log and chocolatey.1.log file that are ~15 MB in size.

System Details

Installed Packages

N/A

Output Log

The logs do not contain anything about the log4net error. Just the list command that was run.

image

Additional Context

N/A

pauby commented 3 months ago

This is caused by the permissions in the $env:ChocolateyInstall\logs folder not having write permissions for non-admin users. There isn't anything we can around this. As the logs are continuing to grow, there is nothing being lost. When Chocolatey CLI is next run as an admin user, the logs will rotate as normal.

We should document this error, what it means, that it only happens at log rotation time, and that running once as admin user will resolve it for that rotation.