SimpleLogger.psm1
|
Class SimpleLogger { [String]$logFileName [String]$logFileLocation Logger([String]$logFIleName, [String]$logFileLocation) { Write-Verbose ("Constructing SimpleLogger Class instance with parameters 1: $logFileName 2: $logFileLocation") $this.logFileName = $logFileName $this.logFileLocation = $logFileLocation $this.Initialize() $this.AddLog("Log file created.") } Initialize() { Write-Verbose "Initializing Logger instance" if (!(Test-Path $this.logFileLocation)) { Write-Verbose "Log file not found, creating a new one" New-item -ItemType File $this.logFileLocation -Force } } AddLog([String]$newLog) { Write-Verbose ("Adding a new log: " + $newLog) "[" + (Get-Date) + ":] " + $newLog | Add-Content $this.logFileLocation } } |