June 8, 2009

Log4Net and Powershell

Sure, why not! To be honest, I see no reason as we have other options in Powershell. Here is how you would do it:
Add-Type -Assembly System.Configuration
[System.Reflection.Assembly]::LoadFrom($MY_DIR + "\lib\log4net.dll")

#Reset
[log4net.LogManager]::ResetConfiguration()
#Configure
[log4net.Config.BasicConfigurator]::Configure()
$log = [log4net.LogManager]::getLogger("POShTest")

if($log.IsDebugEnabled)
{
$log.debug("Debug!")
}

$log.info("Info!")
$log.warn("Warn!")
$log.error("Error!")
$log.fatal("Fatal")

No comments:

Post a Comment