I was working on a project in which I had to create a script to do some solution deployment, site creations etc., and while doing these the script shoul create log file to log entire process. This is a sample script which i worked out and could be useful to all needy.
This script has 3 functions those will be taking care of generating log files.
- LogInfo: General information will be logged, it is called as and when a normal process is completed.
- LogError: Errors will be logged, it is called when an error is encountered.
- ConfigureLogger : This function is for configuring Log:
- The directory where the logs will be stored
- Name of the log file
- Pattern of writing the log file
In this script i have taken SharePoint Admin & Timer service for example, the script will start these two service if they are not and log the same in log file.
I have attached the script, please change the extension of the file prior executing.