Log cannot rotate when Chocolatey CLI is run by non-admin
- Dominant language
- C#
- Stars
- 11.5k
- Forks
- 960
- PR merge metrics
- No merged PRs in 30d
Description
### Checklist
- [X] I confirm there are no unresolved issues reported on the [Chocolatey Status page](https://status.chocolatey.org).
- [X] I have verified this is the correct repository for opening this issue.
- [X] I have verified no other issues exist related to my problem.
- [X] I have verified this is not an issue for a specific package.
- [X] I have verified this issue is not security related.
- [X] 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.
```powershell
$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.)
3. Check the log files sizes (`ls c:\programdata\chocolatey\logs`) to see they're about 15 MB
4. 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
- 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
```bash
N/A
```
### Output Log
The logs do not contain anything about the log4net error. Just the list command that was run.

### Additional Context
N/A
Contributor guide
Research direction
Reproduce the issue by filling `C:\ProgramData\chocolatey\logs\chocolatey.log` and `choco.summary.log`, then running `choco list | Out-Null` from a non-administrator PowerShell session. Compare this with an Administrator session and inspect the log rotation behavior around the two named log files. Done means non-admin execution rotates both logs without emitting the log4net error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100