[UPDATE 2015-12-22] The module is now available on PowerShell Gallery.
[UPDATE 2014-11-15] The module is now available on NuGet.
This module allows you to have a unified logging in PowerShell and all your scripts. It depends on log4net and thus provides great flexibility on how and where you log. Basic usage is as follows:
- Main configuration is defined in the module configuration file (biz.dfch.PS.System.Logging.xml, same base name as the module biz.dfch.PS.System.Logging.psm1 file).
- Log Appenders are defined in the Log4netConfiguration.xml file, all generic logging configuration can be done there.
By default, messages will be logged to C:\Logs\biz.dfch.PS.System.Logging\yyyy-MM\yyyy-MM-dd.log (so every month a subfolder and every day a separate log file).
You need to download log4net dll separately from Apache and place it in the same directory as the module.
- Start logging by using one of the Log-* aliases like, “Log-Debug ‘function’ ‘message’;” or “Log-Critical ‘function’ ‘message’;”.
Use BareTail or a similar tool to view the logs or log them directly to splunk or GrayLog2 (via the Gelf4net UDP Appender).
The concept of the Log-* cmdlets is that you have a “message” part (as with other logging frameworks as well) and a “function” part that you can/must use to indicate in the log from which function or module the log message came from.
- Use Get-Help for the individual commands to get some more help or examples on how to use it.
You can download the module on Github or get it on NuGet with ‘Install-Package biz.dfch.PS.System.Logging‘.
2 Comments »