Created
June 9, 2015 14:25
-
-
Save ploegert/8fc7a0595a20542c6c51 to your computer and use it in GitHub Desktop.
Utilities for logging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Utilities for logging. | |
| NOTE: This module is used by the install script, which must run on PowerShell 2.0 | |
| Be sure to test any changes to this module using PS 2.0. | |
| #> | |
| Set-StrictMode -Version latest | |
| $ErrorActionPreference = 'stop' | |
| <# | |
| .Synopsis | |
| Returns the path of the file to which the extension's output should be redirected | |
| #> | |
| function Get-LogFile | |
| { | |
| $handlerEnvironment = Get-HandlerEnvironment | |
| $sequenceNumber = Get-HandlerExecutionSequenceNumber | |
| $timestamp = Get-Date -UFormat '%Y%m%d-%H%M%S' | |
| '{0}\DscExtensionHandler.{1}.{2}.log' -f $handlerEnvironment.logFolder, $sequenceNumber, $timestamp | |
| } | |
| <# | |
| .Synopsis | |
| A simple wrapper around Write-Verbose that adds a timestamp | |
| #> | |
| function Write-Log | |
| { | |
| param( | |
| [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] | |
| [AllowEmptyString()] | |
| [string] | |
| $Message | |
| ) | |
| Write-Verbose -Verbose ("[{0:s}] {1}`r`n" -f (get-date), $Message) | |
| } | |
| Export-ModuleMember -Function Get-LogFile, Write-Log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment