No XML log file using PowerShell and the .NET Assembly

Advertisement

T
Joined:
Posts:
2
Location:
US

No XML log file using PowerShell and the .NET Assembly

I'm trying to log transfers by modifying one of the supplied scripts in the script examples section. My transfers, and everything else works fine, but when I define:

$session.XmlLogPath = "D:\some\path\here.xml"

and run my script, the files get transferred, and I have a SessionLog...but no XML log. After the script is run, I run:

$session

to see what is defined, and the XmlLogPath is empty?

ExecutablePath                : 
AdditionalExecutableArguments : 
DefaultConfiguration          : True
DisableVersionCheck           : True
IniFilePath                   : 
ReconnectTime                 : 10675199.02:48:05.4775807
DebugLogPath                  : 
SessionLogPath                : D:\some\path\log.log
XmlLogPath                    : 
Timeout                       : 00:01:00
Output                        : {winscp> option batch on, batch           on        , winscp> option confirm off, confirm         off       ...}
Opened                        : 
UnderlyingSystemType          : WinSCP.Session

Below is what I have defined as my session and sessionOptions:



# Load WinSCP .NET assembly
    [Reflection.Assembly]::LoadFrom("D:\Program Files (x86)\WinSCP\WinSCPnet.dll") | Out-Null
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "1.2.3.4" <-- obviously not real IP
    $sessionOptions.UserName = "someftpusername"
    $sessionOptions.Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bPswd)
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx::xx" <-obviously not real fingerprint
 
    $session = New-Object WinSCP.Session
    $Session.DisableVersionCheck = "1"
    $Session.XmlLogPath = "D:\some\path\log.xml"
    $Session.SessionLogPath = "D:\some\path\.log"


Thoughts?

:edit: Removed a "#" from where I was testing something and forgot to uncomment the line before posting the code snippet.
Last edited by T on 2014-03-27 15:44; edited 1 time in total

Reply with quote

Advertisement

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

Re: No XML log file using PowerShell and the .NET Assembly

The XML log file in used internally by the assembly. It is always created (no matter if you set the property or not) and deleted when session closes. The sole purpose of the property is to change a path where the temporary log is stored.

Reply with quote

T
Joined:
Posts:
2
Location:
US

Re: No XML log file using PowerShell and the .NET Assembly

martin wrote:

The XML log file in used internally by the assembly. It is always created (no matter if you set the property or not) and deleted when session closes. The sole purpose of the property is to change a path where the temporary log is stored.

Ok, when I set the XML Log path via the GUI, and perform an action, the .xml log is saved.

<?xml version="1.0" encoding="UTF-8"?>
<session xmlns="http://winscp.net/schema/session/1.0" name="ftpusername@1.2.3.4" start="2014-03-26T19:04:02.852Z">
  <rm>
    <filename value="/TEST/test.txt" />
    <result success="true" />
  </rm>
</session>

I was looking to use the .xml log as opposed to the session.log because it's so much less garbled (a lot easier to read). What method is best for logging and archiving session uploads (success and failure)? I haven't had much luck finding information about logging in regards to PowerShell and the .NET Assembly.

thanks for the speedy response prikryl

Reply with quote

Advertisement

You can post new topics in this forum