Last active
December 19, 2019 10:00
-
-
Save atao/1ab32d886688c706cba315bc0739c12d to your computer and use it in GitHub Desktop.
Fonctions de journalisation #PowerShell
This file contains 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
#region Journalisation | |
function initLog { | |
param( | |
[string]$loggerPath = "$PSScriptRoot\file.log" | |
) | |
if (!(Test-Path $loggerPath)){New-Item -Path $loggerPath -ItemType File} | |
loggerInfo "-----------------------------------------------" $loggerPath | |
loggerInfo "+ Programme : BackupAndSend" $loggerPath | |
loggerInfo "+ Version : 18/12/2019" $loggerPath | |
loggerInfo "-----------------------------------------------" $loggerPath | |
} | |
function loggerInfo { | |
Param ( | |
[parameter(Mandatory = $true)][string]$msg, | |
[string]$loggerPath = "$PSScriptRoot\file.log" | |
) | |
# Verification de la presence du chemin temporaire de l'utilisateur | |
If (Test-Path -Path $loggerPath) | |
{ | |
# Recuperation de la date actuelle | |
$dateActuelle = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
"$dateActuelle [INFO] $msg" | Out-File -FilePath $loggerPath -Append | |
If (!($?)) | |
{ | |
loggerErreur "Impossible d'écrire dans le fichier $loggerPath" | |
} | |
} | |
Else | |
{ | |
loggerErreur "Impossible de trouver le chemin $loggerPath" | |
} | |
} | |
function loggerErreur { | |
Param ( | |
[parameter(Mandatory = $true)][string]$msg, | |
[string]$loggerPath = "$PSScriptRoot\file.log" | |
) | |
# Verification de la presence du chemin temporaire de l'utilisateur | |
If (Test-Path -Path $loggerPath) | |
{ | |
# Recuperation de la date actuelle | |
$dateActuelle = Get-Date -Format "yyyy-MM-dd HH:mm:ss" | |
"$dateActuelle [ERROR] $msg" | Out-File -FilePath $loggerPath -Append | |
If (!($?)) | |
{ | |
loggerErreur "Impossible d'écrire dans le fichier $loggerPath" | |
} | |
} | |
Else | |
{ | |
loggerErreur "Impossible de trouver le chemin $loggerPath" | |
} | |
} | |
#endregion Journalisation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment