SimplePSLogger.File/SimplePSLogger.File.psm1
<#
.SYNOPSIS File logging provider for SimplePSLogger logger This provider writes colored messages to the console by using powershell's default Write-* functions .DESCRIPTION TODO: add more details More details .PARAMETER Name SimplePSLogger action execution id which is used to identify executing action .PARAMETER Level Log level : allowed values are - "verbose", "debug", "information", "warning", "error", "critical", "none" TODO : add more infor for each level .PARAMETER Message Log message : String - plain text string OtherTypes - json serialized string .PARAMETER Config Required configuration provided by user .EXAMPLE TODO : Add examples .NOTES Author: Ganesh Raskar #> function New-File-Logger { [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Name of the SimplePSLogger instance")] [string] $Name, [Parameter(Mandatory = $false, HelpMessage = "Log level, default value is information")] [string] $Level, [Parameter(Mandatory = $true, HelpMessage = "Log message")] [string] $Message, [Parameter(Mandatory = $false, HelpMessage = "Configuration object")] [object] $Config ) $logMessage = "$((Get-Date).ToUniversalTime().ToString("yyyy/MM/dd HH:mm:ss:ffff tt")) $Name $($Level) $($Message.Trim())" <# TODO : Robust error handling and config validation #> if (-Not $Config -or -Not $($Config["LiteralFilePath"])) { $filePath = Join-Path $([system.io.path]::GetTempPath()) -ChildPath "$Name.log" Write-Information "File provider does not have LiteralfilePath configured, switching to auto generated file here $filepath" } else { $filePath = $($Config["LiteralFilePath"]) } Add-Content $filePath $logMessage -Encoding 'UTF8' } Export-ModuleMember -Function New-File-Logger # SIG # Begin signature block # MIIYYQYJKoZIhvcNAQcCoIIYUjCCGE4CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUIZAj8Hcst2Im6OGphZx7X/S8 # ZC2gghKzMIIFcDCCA1igAwIBAgIQZDtcNubuNpVEfXOVHbciTzANBgkqhkiG9w0B # AQsFADBQMSUwIwYDVQQDDBxHYW5lc2ggUmFza2FyIFNpbXBs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IICCwYJKoZIhvcNAQkGMYIB/DCCAfgCAQEwdjBiMQswCQYDVQQGEwJV # UzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQu # Y29tMSEwHwYDVQQDExhEaWdpQ2VydCBBc3N1cmVkIElEIENBLTECEAMBmgI6/1ix # a9bV6uYX8GYwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEw # HAYJKoZIhvcNAQkFMQ8XDTIwMDcwNDIwNDgwMlowIwYJKoZIhvcNAQkEMRYEFBeo # 9X/Uygjkbah76nfUCLsTxKGrMA0GCSqGSIb3DQEBAQUABIIBAEpZUvmE6uY5ussu # ROF/9xUPq91ieejVjda/YnCjrQsk8iyEJq8IDDTpnQYc28KYV7UIV/kp/QO2LqFb # 1/H8xYnPoPUaIZLxG+jGe404OHmOzs5XgM5zbehHIV/LOBSe1rhYxZ61PPJisQcN # capnjjouzLVhaTjUcDJKLJ62RoDCJRvOPD7OL9S5PmyEVjbtdkX403Tg6cgw160w # D+Uf+HroRy3CCXIieKF4Hw+J99xDthUnDKZ2aKTj4KpIQxysBgcYak8pODrfiiW4 # aA5fWzDAgkz3jD7NFatjzjzU7BTjq0Tir6TTbBDs1MK7h0j2Ao3mg4s6rICtd52G # nWa4Ijw= # SIG # End signature block |