Demo 2* -Setup of a ColoredConsoleAppender as a default appender.
.\InitializeLG4N.ps1 
  # $DebugPreference="Continue"

  #Create a new logger
$Log = Get-LogLogger "LogPowerShell"

 #Declare the colors used by a ColoredConsoleAppender
 #The hashTable must respect the following structure :  @{Level="";FColor="";BColor=""}
[System.Collections.Hashtable[]] $Colors1=@(
   @{Level="Warn";FColor="Yellow";BColor=""},
   @{Level="Info";FColor="Cyan";BColor=""},
   @{Level="Debug";FColor="Green,HighIntensity";BColor=""},
   @{Level="Error";FColor="Red";BColor="Red,HighIntensity"}
 )
     
$Pattern = "%date{dd-MM-yyyy } %-5level - %message%newline"

  #Configure the log4net framework with the appender previously created in the pipeline
  #This appender becomes the default appender
  #Activate must be used, see Appender.ActivateOptions 
New-LogColoredConsoleAppender $Colors1 $Pattern -Activate|Set-LogBasicConfigurator 

$Log.Info("TestMessage1");

[System.Collections.Hashtable] $Colors=@{
   PSDefault=@( 
     @{Level="Warn";FColor="Yellow";BColor=""},
     @{Level="Info";FColor="Cyan";BColor=""},
     @{Level="Debug";FColor="Green";BColor=""},
     @{Level="Error";FColor="Red";BColor=""}
    )

   Testing=@(
     @{Level="Warn";FColor="Yellow";BColor=""},
     @{Level="Info";FColor="Green,HighIntensity";BColor=""},
     @{Level="Debug";FColor="Cyan";BColor=""},
     @{Level="Error";FColor="Red";BColor=""}
     @{Level="Fatal";FColor="Red";BColor="Red,HighIntensity"}
  )
 }

 
$Appender=New-LogColoredConsoleAppender $Colors.Testing $Pattern -Activate|Set-LogBasicConfigurator 
$Log.Info("TestMessage2");

 #Add a color, ActivateOptions must be called with Enable-LogAppender
$Appender|Add-LogMappingColors $Appender @{Level="Info";FColor="red";BColor="HighIntensity"}|Enable-LogAppender
$Log.Info("TestMessage3");

  # call [log4net.LogManager]::ResetConfiguration()
  # close all appenders.
Stop-Log

Last edited Feb 24, 2009 at 10:44 AM by Batchman, version 4

Comments

No comments yet.