Session log file rotation macro (e g add day, hour)

Advertisement

r4v3n
Joined:
Posts:
11
Location:
Stockholm, Sweden

Session log file rotation macro (e g add day, hour)

We have some issue where same session log file is reused by same integration flow (same destination). One destination has one optional session log file. In many cases the customer needs to keep the log enabled all the time as they need to prove that the transfer was made later when others complain. This is the WinSCP session log. The problem is when using the same session log is that it is locked when in use and it is getting really large which slows down eventually and you need to stop everything to unlock the file and move it to generate a new one.

I don't see any macros documented for the session log. Is it possible to specify a macro to make WinSCP divide the session log automatically? Would it be possible to add this feature in the future if not possible? I see a need for daily and hourly macro for this:
https://winscp.net/eng/docs/library_session#sessionlogpath

e g something like this:
C:\temp\SFTPLocation1-%yyyy%-%MM%-%dd%-%hh%.txt
C:\temp\SFTPLocation1-%yyyy%-%MM%-%dd%.txt

Or new property, e g SessionLogRotationPeriod:
None (default)
Daily
Hourly

Reply with quote

Advertisement

r4v3n
Joined:
Posts:
11
Location:
Stockholm, Sweden

I mean the log gets really huge and is hard to read, and the process using it, needs to be stopped before it can be manually archived.

I see here, that there is macro in UI:
https://winscp.net/eng/docs/ui_pref_logging#session_log
Would it be possible to add these to scripting (library, SessionLogPath) as well?
Log file name can contain following patterns: !Y (year), !M (month), !D (day), !T (time), !@ (hostname), !S (session name), !P (process ID), !! (exclamation mark).
Would it be possible to add also new library scripting parameter for the log rotation on size as well? (similar to UI/command line)

When I try to set SessionLogPath to this: "c:\temp\sftpsessionlog-!Y!M!D.txt"
Then WinSCP automatically changes it to this (according to the session log):
/log="c:\temp\sftpsessionlog-!!Y!!M!!D.txt"
and then I get only a session log file like this: "c:\temp\sftpsessionlog-!Y!M!D.txt"
so it doesn't add the year, month, day which was intended.

Reply with quote

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

r4v3n wrote:

Would it be possible to add also new library scripting parameter for the log rotation on size as well?
See https://winscp.net/eng/docs/rawconfig#logmaxsize

When I try to set SessionLogPath to this: "c:\temp\sftpsessionlog-!Y!M!D.txt"
...
I assume you use WinSCP .NET assembly from some high-level language, right? So use features of your language to format the session log path to include the timestamp you want.

Reply with quote

r4v3n
Joined:
Posts:
11
Location:
Stockholm, Sweden

Thanks for the update. Currently we pass through the session log file name so it can be changed by anyone so if WinSCP allow other future macro changes anyone could change this. So it would be great if you could support the macros also in this automation .NET scenario like we have in the GUI options in same way.

After testing with the max log size rotation (Logging\LogMaxSize), it gives errors so unfortunately this cannot be used in automation scenario it seems. It only works for single session, but as soon as there are multiple sessions errors like these happens:
System.TimeoutException: Timeout waiting for WinSCP to respond
   at WinSCP.Session.CheckForTimeout(String additional)
   at WinSCP.PatientFileStream.Wait(Int32& interval)
   at WinSCP.PatientFileStream.Read(Byte[] array, Int32 offset, Int32 count)
   at System.Xml.XmlTextReaderImpl.ReadData()
   at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
   at System.Xml.XmlTextReaderImpl.ParseText()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at WinSCP.SessionLogReader.DoRead()
   at WinSCP.SessionLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.Read(LogReadFlags flags)
   at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
   at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
   at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags)
   at WinSCP.Session.WaitForGroup()
   at WinSCP.Session.Open(SessionOptions sessionOptions)

The process cannot access the file because it is being used by another process
   at WinSCP.SessionLogReader.Read(LogReadFlags flags)
   at WinSCP.ElementLogReader.Read(LogReadFlags flags)
   at WinSCP.SessionElementLogReader.Read(LogReadFlags flags)
   at WinSCP.CustomLogReader.TryWaitForNonEmptyElement(String localName, LogReadFlags flags)
   at WinSCP.CustomLogReader.WaitForNonEmptyElement(String localName, LogReadFlags flags)
   at WinSCP.Session.WaitForGroup()
   at WinSCP.Session.Open(SessionOptions sessionOptions)

Reply with quote

Advertisement

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

r4v3n wrote:

Thanks for the update. Currently we pass through the session log file name so it can be changed by anyone so if WinSCP allow other future macro changes anyone could change this. So it would be great if you could support the macros also in this automation .NET scenario like we have in the GUI options in same way.
What do you mean by "pass through"? Do you mean that the log file for WinSCP is configurable in your application/script/whatever? So implement placeholders in your code.

After testing with the max log size rotation (Logging\LogMaxSize), it gives errors so unfortunately this cannot be used in automation scenario it seems. It only works for single session, but as soon as there are multiple sessions errors like these happens:
...
Please post debug and session log files.

Reply with quote

Advertisement

You can post new topics in this forum