# WinSW Logging and Error Reporting ### Logging Winsw supports several different ways to capture stdout and stderr from the process you launch. ### Log directory The `` element specifies the directory in which the log files are created. If this element is absent, it'll default to the same directory where the configuration file resides. ### Append mode (default) In this mode, *myapp.out.log* and *myapp.err.log* (where *myapp* is the base name of the executable and the configuration file) are created and outputs are simply appended to these files. Note that the file can get quite big. ```xml ``` ### Reset mode Works like the append mode, except that every time the service starts, the old log files are truncated. ```xml ``` ### Ignore mode Throw away stdout and stderr, and do not produce any log files at all. ```xml ``` ### Rotate mode Works like the append mode, but in addition, if the log file gets bigger than a set size, it gets rotated to *myapp.1.out.log*, *myapp.2.out.log* and so on. The nested `` element specifies the rotation threshold in KB (defaults to 10MB), and the nested `` element specifies the number of rotated files to keep (defaults to 8.) ```xml 10240 8 ``` ### Rotate by time mode Works like the rotate mode, except that instead of using the size as a threshold, use the time period as the threshold. This configuration must accompany a nested `` element, which specifies the timestamp pattern used as the log file name. ```xml yyyyMMdd ``` The syntax of the pattern string is specified by [DateTime.ToString()](http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx). For example, in the above example, the log of Jan 1, 2013 gets written to `myapp.20130101.out.log` and `myapp.20130101.err.log`. ### Rotate by size and time mode Works in a combination of rotate size mode and rotate time mode, if the log file gets bigger than a set size, it gets rotated using `` provided. ```xml 10240 yyyyMMdd 00:00:00 5 yyyyMM ``` The syntax of the pattern string is specified by [DateTime.ToString()](http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx). For example, in the above example, the log of Jan 1, 2013 gets written to `myapp.20130101.out.log` and `myapp.20130101.err.log`. The syntax of the autoRollAtTime is specified by [TimeSpan.ToString()](https://msdn.microsoft.com/en-us/library/1ecy8h51(v=vs.110).aspx). For example, in the above example, at the start of the day it will roll the file over. The `zipOlderThanNumDays` can only be used in conjection with autoRollAtTime, provide the number of days of files to keep. ```xml 00:00:00 5 ``` The zipDateFormat can only be used in conjection with autoRollAtTime, provide the zip file format using the [DateTime.ToString()](http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx). ```xml 00:00:00 yyyyMM ``` ### Error reporting WinSW uses WMI underneath, and as such it uses its error code as the exit code. See [Create method of the Win32_Service class](https://docs.microsoft.com/windows/win32/cimwin32prov/create-method-in-class-win32-service) for the complete list of exit code. When winsw is running as a service, more detailed error information is reported to the Windows event log.