Can’t Set Debug Log Path

Advertisement

aksarben
Joined:
Posts:
72

Can’t Set Debug Log Path

I’m getting a strange error creating a Session object. Here's the code:
function New-Session {
   [WinSCP.Session]$session = New-Object WinSCP.Session 
   $sessionLogPath = $env:TchPublisherSessionLogPath
   if ($sessionLogPath) {
      if (!(Test-Path $sessionLogPath)) {
         Deny-EnvironmentVariable -description "Session log path" -variable "TchPublisherSessionLogPath" -reason $PATH_DOES_NOT_EXIST
      }
      $session.sessionLogPath = $sessionLogPath
   }
   $debugLogPath = $env:TchPublisherDebugLogPath
   if ($debugLogPath) {
      if (!(Test-Path $debugLogPath)) {
         Deny-EnvironmentVariable -description "debug log path" -variable "TchPublisherDebugLogPath" -reason $PATH_DOES_NOT_EXIST
      }
      $session.debugLogPath = $debugLogPath
   }
   $debugLogLevel = $env:TchPublisherLogLevel
   if ($debugLogLevel) {
      if ($debugLogLevel -lt -1 -or $debugLogLevel -gt 1) {
         Deny-EnvironmentVariable -description "log level" -variable "TchPublisherLogLevel" -reason "valid values are -1 to 1"
      }
      $session.debugLogLevel = $debugLogLevel
   }
   return $session
}
I consistently get an error on this line:
$session.debugLogPath = $debugLogPath
The error message:
Exception setting "debugLogPath": "Access to the path 'C:\Users\Dick\Documents\PowerShell\Scripts' is denied."
The path I was going to store for debugLogPath was the same one I just set for sessionLogPath.
I didn’t see anything in the documentation that the two paths have to be different. What am I doing wrong?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,415
Location:
Prague, Czechia

Re: Can’t Set Debug Log Path

It's path to a log file, not a path to a directory containing the log file.
So it should be like:
$session.DebugLogPath =
    "C:\Users\Dick\Documents\PowerShell\Scripts\WinSCP.debug.log"
Same for Session.SessionLogPath.

Reply with quote

Advertisement

You can post new topics in this forum