Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples showing how to use it #10

Open
deadlydog opened this issue Jul 20, 2020 · 1 comment
Open

Examples showing how to use it #10

deadlydog opened this issue Jul 20, 2020 · 1 comment

Comments

@deadlydog
Copy link

Adding some examples to the ReadMe showing how to use it (not just install it) and what that looks like would be helpful. I (and I imagine others) don't even bother trying out modules/packages when there's no docs showing how to use it. Thanks!

@ayewo
Copy link

ayewo commented Oct 5, 2024

I hunted for the announcement link in the README (which now 404s) on the Internet Archive and found an example of how to use it:

  1. First, install it: Install-Module PowerShellLogging

  2. Save the following code to a file (e.g. test.ps1):

Import-Module PowerShellLogging 
 
$LogFile = Enable-LogFile -Path $env:temp\test.log 
 
# Note - it is necessary to save the result of Enable-LogFile to a variable in order to keep the object alive.  As soon as the $LogFile variable is reassigned or falls out of scope, the LogFile object becomes eligible for garbage collection. 
 
$VerbosePreference = 'Continue' 
$DebugPreference = 'Continue' 
 
Write-Host "Write-Host test." 
"Out-Default test." 
Write-Verbose "Write-Verbose test." 
Write-Debug "Write-Debug test." 
Write-Warning "Write-Warning test." 
Write-Error "Write-Error test." 
Write-Host ""   # To display a blank line in the file and on screen. 
Write-Host "Multi`r`nLine`r`n`r`nOutput"  # To display behavior when strings have embedded newlines. 
 
# Disable logging before the script exits (good practice, but the LogFile will be garbage collected so long as this variable was not in the Global Scope, as a backup in case the script crashes or you somehow forget to call Disable-LogFile). 
 
$LogFile | Disable-LogFile 
  1. Run the sample: .\test.ps1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants