|
2 | 2 |
|
3 | 3 | # ScriptLogger PowerShell Module
|
4 | 4 | PowerShell Module to provide logging capabilities for PowerShell Controller Scripts.
|
| 5 | + |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +With the ScriptLogger module, you are able to log error, warning, informational and verbose log messages into log files, the event log and the console host. |
| 10 | + |
| 11 | + |
| 12 | +## Requirenments |
| 13 | + |
| 14 | +The following minimum requirenments are necessary to use the module: |
| 15 | + |
| 16 | +* Windows PowerShell 3.0 |
| 17 | +* Windows Server 2008 R2 / Windows 7 |
| 18 | + |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +Install the module **automatically** from the [PowerShell Gallery](https://www.powershellgallery.com/packages/ScriptLogger) with PowerShell 5.0: |
| 23 | + |
| 24 | +```powershell |
| 25 | +Install-Module ScriptLogger |
| 26 | +``` |
| 27 | + |
| 28 | +To install the module **manually**, perform the following steps: |
| 29 | + |
| 30 | +1. Download the latest release from [GitHub](https://github.com/claudiospizzi/ScriptLogger/releases) as a ZIP file |
| 31 | +2. Extract the downloaded module into one of your module paths ([TechNet: Installing Modules](https://technet.microsoft.com/en-us/library/dd878350)) |
| 32 | + |
| 33 | + |
| 34 | +## Cmdlets |
| 35 | + |
| 36 | +The module has for cmdlets to manage the logger configuration and four cmdlets to write messages with different levels: |
| 37 | + |
| 38 | +| Cmdlet | Description | |
| 39 | +| ----------------------- | --------------------------------------------------------------- | |
| 40 | +| `Start-ScriptLogger` | Start the script logger inside the current PowerShell session. | |
| 41 | +| `Stop-ScriptLogger` | Stop the script logger inside the current PowerShell session. | |
| 42 | +| `Set-ScriptLogger` | Update the script logger log configuration. | |
| 43 | +| `Get-ScriptLogger` | Get the current script logger object. | |
| 44 | +| `Write-VerboseLog` | Log a verbose message. | |
| 45 | +| `Write-InformationLog` | Log an information message. | |
| 46 | +| `Write-WarningLog` | Log a warning message. | |
| 47 | +| `Write-ErrorLog` | Log an error message. | |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +## Examples |
| 52 | + |
| 53 | +The following example show two options how to start the script logger, the logger management and how to log the log messages. |
| 54 | + |
| 55 | +```powershell |
| 56 | +# Initialize the logger with default values |
| 57 | +Start-ScriptLogger |
| 58 | +
|
| 59 | +# Second options, specify multiple custom settings for the logger |
| 60 | +Start-ScriptLogger -Path 'C:\Temp\test.log' -Format '{0:yyyy-MM-dd} {0:HH:mm:ss} {1} {2} {3,-11} {4}' -Level Warning -SkipEventLog -HideConsoleOutput |
| 61 | +
|
| 62 | +# Get the current script logger configuration object |
| 63 | +Get-ScriptLogger |
| 64 | +
|
| 65 | +# Update the script logger configuration |
| 66 | +Set-ScriptLogger -Level Verbose |
| 67 | +
|
| 68 | +# Log an error message |
| 69 | +Write-ErrorLog -Message 'My Error Message' |
| 70 | +
|
| 71 | +# Log a warning massage |
| 72 | +Write-WarningLog -Message 'My Warning Message' |
| 73 | +
|
| 74 | +# Log an information message |
| 75 | +Write-InformationLog -Message 'My Information Message' |
| 76 | +
|
| 77 | +# Log a verbose message |
| 78 | +Write-VerboseLog -Message 'My Verbose Message' |
| 79 | +
|
| 80 | +# Disable the logger |
| 81 | +Stop-ScriptLogger |
| 82 | +``` |
| 83 | + |
| 84 | + |
| 85 | +## Contribute |
| 86 | + |
| 87 | +Please feel free to contribute by opening new issues or providing pull requests. |
0 commit comments