Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks done
pauby opened this issue Mar 21, 2024 · 1 comment
Open
6 tasks done

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

pauby opened this issue Mar 21, 2024 · 1 comment

Comments

@pauby
Copy link
Member

pauby commented Mar 21, 2024

Checklist

  • I confirm there are no unresolved issues reported on the Chocolatey Status page.
  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.
  • I confirm I am using official, and not unofficial, or modified, Chocolatey products.

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()
  1. 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.)
  2. Check the log files sizes (ls c:\programdata\chocolatey\logs) to see they're about 15 MB
  3. 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.
  1. Check the log file sizes again to see that they are now much less (my test system were 388 and 12,202 bytes)
  2. 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

  • Operating System: 10
  • Windows PowerShell Version: 5.1
  • Chocolatey CLI Version: 2.2.2
  • Chocolatey Licensed Extension version: N/A
  • Chocolatey License type (Professional / Business / ?): N/A
  • Terminal/Emulator: conhost

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
Copy link
Member Author

pauby commented Mar 21, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant