This project is read-only.

Is there a way to disable logging?

Topics: Archive - General
Mar 11, 2015 at 4:31 PM
I have a use case where I'm needing to turn off psappdeploykit logging. Is there an easy way to do this?
Mar 11, 2015 at 5:10 PM
Edited Mar 11, 2015 at 5:15 PM
Well AppDeployToolkitMain.ps1 does have DisableLogging as a parameter
[switch]$DisableLogging = $false,
but it also has this conflicting chunk of code (So Devs, is it set in Param or as part of the code? )
        ## Initialize $DisableLogging variable to avoid error if 'Set-StrictMode' is set
        If (-not (Test-Path -Path 'variable:DisableLogging')) { $DisableLogging = $false }
Anyhow, for your purposes, it is doable. The problem is that it's not that clean and easy to do it as it should.
It's also not very useful to turn off logging so I can understand why they didn't bother to test it.
Why have scripts run blind and not have logs to know what happened when things go wrong?
But you have your reasons, right?


Any how, without actually testing it, I would try these 2 things:

Option 1: declare $DisableLogging in Deploy-Application.ps1 before it Dot sources AppDeployToolkitMain.ps1
In Deploy-Application.ps1 add this:
[switch]$DisableLogging = $true
Before this chunk of code
    ## Dot source the required App Deploy Toolkit Functions
    Try {
        [string]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
        If (-not (Test-Path -Path $moduleAppDeployToolkitMain -PathType Leaf)) { Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]." }
        . $moduleAppDeployToolkitMain
    }
    Catch {
        [int32]$mainExitCode = 1
        Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
        Exit $mainExitCode
    }
Somehow, I don't have "warm and fuzzy feelings" that Option 1 will work so...



Option 2: Modify Deploy-Application.ps1 by adding -DisableLogging when it Dot sources AppDeployToolkitMain.ps1
    ## Dot source the required App Deploy Toolkit Functions
    Try {
        [string]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
        If (-not (Test-Path -Path $moduleAppDeployToolkitMain -PathType Leaf)) { Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]." }
        . $moduleAppDeployToolkitMain -DisableLogging
    }
    Catch {
        [int32]$mainExitCode = 1
        Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
        Exit $mainExitCode
    }
I'm more confident that this will work but this is modifying one of the "Do not touch" sections of Deploy-Application.ps1

Option 3: Spoof it!

Edit AppDeployToolkitConfig.xml and change the log file location to %temp% where nobody will look
    <Toolkit_LogPath>$envTemp</Toolkit_LogPath>


NOTE: The source I posted is from the most current v3.6 beta so it might not match 100% but the $DisableLogging variable name probably has not been changed since v3.5.
Mar 12, 2015 at 2:20 AM
If you set variable $DisableLogging = $true before the toolkit is dot sourced as in option 1 specified in above post, then logging will be disabled. Note: this variable is initialized to $false in the Write-Log function if it is not set anywhere else to avoid an error that would be thrown only if Set-StrictMode option is used.
Mar 12, 2015 at 4:30 PM
Hi Mo, glad to to see you back.

Maybe in Deploy-Application.ps1 for v3.7, you could add a line:
[switch]$DisableLogging = $False
This way, new users of PSADT could quickly determine that logging can be disabled by changing that one line in Deploy-Application.ps1

What do you think?
Mar 13, 2015 at 1:16 AM
Hey, glad to be back. Yes, I agree, I think that is a good idea. I will create an issue for it.
Mar 13, 2015 at 1:17 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.