Nebula.Log is a lightweight and configurable logging module for PowerShell scripts.
- Logging with levels:
INFO,SUCCESS,WARNING,DEBUG,ERROR - Output to both console and log file (you can also choose to output only on log file using
-WriteOnlyToFileswitch) - Auto-archives log file if it exceeds 512 KB
- You can test the logging setup using
Test-ActivityLogfunction (read more) - Includes alias
Log-Message(to callWrite-Logfunction)
Install from the PowerShell Gallery:
Install-Module -Name Nebula.Log -Scope CurrentUserBasic example (output to both console and log file):
Write-Log -LogLocation "C:\Logs" -Message "Starting script ..." -Level "INFO" -WriteToFileBasic example (output to log file only):
Write-Log -LogLocation "C:\Logs" -Message "Starting script ..." -Level "INFO" -WriteToFile -WriteOnlyToFileTesting the logging setup:
Test-ActivityLog -LogLocation "C:\Logs"This function validates the availability and write capability of a specified activity log file.
Test-ActivityLog -LogLocation <String> [-LogFileName <String>]-
LogLocation(String, Required)
The directory where the log file is expected to be located. -
LogFileName(String, Optional)
The name of the log file. Defaults toactivity.logif not specified. -
TryFix(Switch, Optional)
If theactivity.logfile is not writable, the function tries to rename the old file and create a new one where new log messages can be written.
Test-ActivityLog checks whether the specified log file exists and is writable by the current user. If the file doesn't exist or is not writable, it returns "KO" and writes an error. If everything is in order, it appends a test entry and returns "OK". You can also use TryFix switch in case the file is not writable, to attempt an automatic repair.
This is useful for automated checks or pre-flight validations before starting logging operations.
Test-ActivityLog -LogLocation "C:\Logs"Returns "OK" if C:\Logs\activity.log exists and is writable, otherwise "KO".
Test-ActivityLog -LogLocation "C:\Logs" -TryFixTry renaming the old, damaged, non-writable file so that you can create a new one in which to keep track of new log messages.
Invoke-Pester -Script .\Nebula.Log.Tests.ps1When updating from previous versions, old files (such as unused .psm1, .yml, or LICENSE files) are not automatically deleted.
If you want a completely clean setup, you can remove all previous versions manually:
# Remove all installed versions of the module
Uninstall-Module -Name Nebula.Log -AllVersions -Force
# Reinstall the latest clean version
Install-Module -Name Nebula.Log -Scope CurrentUser -Forceℹ️ This is entirely optional — PowerShell always uses the most recent version installed.
All scripts in this repository are licensed under the MIT License.
This module is part of the Nebula PowerShell tools family.
Feel free to fork, improve and submit pull requests.
Feedback, suggestions, and pull requests are welcome!
Feel free to open an issue or contribute directly.