Redirecting Logs in Windows Batch File to a Log File

If you simply want to redirect all your logs to a Log.txt file, use the following script and save it as a ".bat" file.
@echo off
SET LOGFILE="Log.txt"
call :Logit >> %LOGFILE%
exit /b 0
:Logit
ECHO ########This is a Log######################################

Now Run the batch file that you have created. You will see the logs in a Log.txt file.

If you want to Create the Log file with date time stamp, then use the following script and save it as a batch file.

 @echo off 
SET LOGFILE="LOG-%date%-%time:~0,2%-%time:~3,2%-%time:~6,2%.txt" 
call :Logit >> %LOGFILE% 
exit /b 0 
:Logit 
ECHO ########This is a Log######################################

This will create the LOG-YYYY-MM-DD-HH-MM-SS.txt file for you.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s