Rotating the Log File on Demand

In some applications, you may want Serial Logger Service to create a new log file at unpredictable times whenever you need the data. For instance, you may want to run a simple program or batch file (.CMD or .BAT) that will import the current log file and then have Serial Logger Service start using a new blank log file.

The batch file below is an example that will move the latest Serial Logger Service log file (called pbx.txt) to an import directory that another appliication (such as a PBX call analysis program) will import from. It is expected that this other application will delete or move the file from the import directory after it has successfully imported the file.

Note: This batch file assumes that Serial Logger Service is configured to NOT use periodic log rotation. The Log Rotation setting should be set to None.

This batch file performs the following steps:

  1. Checks to see if the file c:\ToImport\pbx.txt already exists. If it does, then the batch file stops because otherwise it would overwrite a file which hasn't been imported, yet.
  2. Pauses the first instance of Serial Logger Service.
  3. Moves the latest log file pbx.txt to c:\ToImport\pbx.txt.
  4. Continues the service.
@echo off
if exist c:\ToImport\pbx.txt goto :alreadyexists
net pause seriallogger1
move "c:\Program Files\Serial Logger Service\pbx.txt" c:\ToImport
net continue seriallogger1
goto :end

:alreadyexists
echo.
echo Cannot copy latest data because the import file already exists
echo in the import directory.
echo.

:end