Logging
powerEvents uses Apache log4net as core logging library, and additionally PostSharp Diagnostics for extended Debug logging.
By default, all the logs are stored in a logfile located in ‘C:Users\{USER}\AppData\Local\coolOrange\powerEvents\Logs\powerEvents.log’ and it contains only Infos, Warnings and Errors.
The log4net settings file is located in C:\Program Files\coolOrange\Modules\powerEvents\powerEvents.log4net.
Further information about log4Net Configurations can be found here.
When to change the logging behavior?
When you have issues with failing script executions or when you want to get a more detailed knowledge about what powerEvents or powerVault cmdlets are doing, you can increase the loglevel.
Note
When changing the loglevel to DEBUG PostSharp Diagnostics will be enabled and will log all the function calls into the log files.
This could cause performance issues.
LogFile
You can see, that there are multiple logging-Appenders used. If you want to change the outputpath or the name of the logfile, please visit following appender:
2 3 4 | <appender name="FileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="${LOCALAPPDATA}\coolOrange\powerEvents\Logs\powerEvents.log" /> |
The logging level for the logfile can be changed in the following lines:
56 57 58 59 60 | <root> <level value="INFO" /> <appender-ref ref="FileAppender"/> <appender-ref ref="ColoredConsoleAppender" /> </root> |
By changing the level to “DEBUG”, log entries wih all the levels between the range Debug and Fatal will be written to the logfile.
This way you can get more details about errors that occur during:
the execution of client customization scripts (within the powerEvents Host)
during the execution of Cmdlets or their -Action parameters (also if in external PSHosts)
To control the logging behaviour of powerVault Cmdlets, the following section is used:
61 62 63 | <logger name="powerVault.Cmdlets"> <level value="INFO" /> </logger> |
Note
When powerVault cmdlet’s are getting used before importing the powerEvents module, not all the powerVault logs can be redirected to the logger configured in the previously mentioned section.
PowerShell IDE
PowerShell IDEs like PowerShell console (and PowerShell ISE) are configured to show the logging levels in a different color.
In order to customize the logging level in the console window, visit following appender:
ColoredConsoleAppender
ColoredConsoleAppenders are working for PowerShell IDE’s that support console windows.
272 | <appender name="ColoredConsoleAppender" type="log4net.Appender.ManagedColoredConsoleAppender"> |
In the lines
50 51 52 53 | <filter type="log4net.Filter.LevelRangeFilter"> <levelMin value="INFO" /> <levelMax value="FATAL" /> </filter> |
you can configure the required logging level. You could set the minimal filter level to “DEBUG”, than all the levels between the range Debug and Fatal will be logged.
This appender allows changing even the colors of the messages, depending on their log level:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <mapping> <level value="DEBUG" /> <foreColor value="Black" /> <backColor value="White" /> </mapping> <mapping> <level value="INFO" /> <backColor value="DarkGreen" /> </mapping> <mapping> <level value="WARN" /> <foreColor value="Black" /> <backColor value="Yellow" /> </mapping> <mapping> <level value="ERROR" /> <backColor value="Red" /> </mapping> <mapping> <level value="FATAL" /> <backColor value="DarkRed" /> </mapping> |