Easy PowerShell Logging with EZLog

October 27, 2023

Hue Truong

If you are looking for a simple and effective way to log your PowerShell scripts, you might want to check out EZLog. EZLog is a PowerShell module that allows you to create and manage log files with minimal code.

With EZLog, you can:

– Write log messages with different levels of severity (Info, Warning, Error)
– Customize the log file name
– Rotate log files
– Include header, footer, timestamps, caller information, and exception details in log messages
– Filter log messages in PowerShell

To use EZLog, you first need to install it from the PowerShell Gallery. You can do this by running the following command:

Install-Module -Name EZLog -Scope CurrentUser

Then, you just need to import the module and call the Write-EZLog cmdlet with your message and level.

For example:

# Import the ezlog module
Import-Module ezlog

$LogFile = 'mylogfile.log'

$PSDefaultParameterValues = @{ 'Write-EZLog:LogFile'   = $LogFile ;
  'Write-EZLog:Delimiter' = ';' ;
  'Write-EZLog:ToScreen'  = $true
}
                            
Write-EZLog -Header
Write-EZLog -Category INF -Message 'This is an info to be written in the log file'
Write-EZLog -Category WAR -Message 'This is a warning to be written in the log file' 
Write-EZLog -Category ERR -Message 'This is an error to be written in the log file'
Write-EZLog -Footer 

In conclusion, we have explored the capabilities of EZLog, a PowerShell module that significantly simplifies the logging process in PowerShell scripts. With its ability to write log messages at various levels of severity, customizable log file settings, and multiple viewing options, EZLog proves to be a versatile tool for any PowerShell scripter. The module can be easily installed from the PowerShell Gallery and utilized with the Write-EZLog cmdlet. This makes EZLog not only a powerful tool but also an accessible one for improving your logging experience in PowerShell. Whether you’re a seasoned scripter or just starting out, EZLog offers a streamlined and efficient way to handle logging in your scripts.

join the conversation

Leave the first comment

Avatar for Hue Truong

Hue Truong

IT Professional, Systems Engineer, and Cloud Administrator. Passionate about exploring the latest technologies and solving complex problems.

Related Posts

More articles like this