TrainingUtils.CSCN.psm1
function Show-Log { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateSet("INFO", "WARNING", "ERROR", "DEBUG", "VERBOSE")] [string]$Type, [Parameter(Mandatory=$true)] [string]$Message ) $TimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $LogMessage = "[$TimeStamp] [$Type]: $Message" Write-Verbose "Mensaje a agregar al Log: $Message" Write-Debug "Debug TimeStamp: [$TimeStamp]" Write-Host $LogMessage } function Write-Log { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [ValidateSet("INFO", "WARNING", "ERROR", "DEBUG", "VERBOSE")] [string]$Type, [Parameter(Mandatory=$true)] [string]$Message, [Parameter(Mandatory=$true)] [string]$LogFilePath ) $VerbosePreference = "Continue" $DebugPreference = "Continue" $TimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $LogMessage = (Write-Verbose "Mensaje a agregar al Log: '$Message'" *>&1).ToString() $LogMessage += "`n" + (Write-Debug "Debug TimeStamp: [$TimeStamp]" *>&1).ToString() $LogMessage += "`n[$TimeStamp] [$Type]: $Message" Save-LogToFile -LogMessage $LogMessage -LogFilePath $LogFilePath } function Save-LogToFile { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$LogMessage, [Parameter(Mandatory=$true)] [string]$LogFilePath ) Add-Content -Path $LogFilePath -Value $LogMessage } |