The next task OpenLog( ) performs is to clear out old log
files. In the app.config file there is a setting which says log files should be
stored for sixty days. Log files older than sixty days are deleted.
Now OpenLog( ) creates a new log file named
[year-month-day-hour-minute-second].txt. If there is already a file with this
name (because the batch job was launched twice in the same second), the second
file will have a "(2)" added to the end of the file name.
Now that we have a folder to hold log files and we've
created a new log file for this run, OpenLog( ) records the time when processing
began.
CloseLog( ) records
the time when processing is complete and then closes the log file.
WriteToLog( ) writes
a string into the log file. Each string thus written goes on its own line in
the log.
The .config file also contains the entries for the
Microsoft Enterprise Library data access block and a connection string. With
these in place, the batch job is ready to connect to a database, as shown in the
Main( ) function.
After a successful run, the batch job exits with a return
code of 0. If it fails while creating the log, it exits with a return code of
1.