Another full-blown solution could be using log4net. Once it is
installed, add this to your profile:
[Reflection.Assembly]::LoadFrom("log4net.dll") # you may want to
adjust the path here
[log4net.Config.XmlConfigurator]::Configure( `
(new-object System.IO.FileInfo -ArgumentList `
(ls "log4net_config.xml").FullName `
) )
$global:Log = [log4net.LogManager]::GetLogger("Powershell.PSTest")
After that, you can use something like $Log.Warn("hello, log")
Read log4net documentation on how to configure the format and location
of log files
Cheers
On Sep 25, 9:50*am, Chris Dent <ch...@newsgroup> wrote:
> Would you want to capture any error returned from the two commands? e.g.
>
> $LogFile = "RemoveItem.log"
>
> Remove-Item $SomeItem -ErrorVariable "RemoveErr"
> If ($RemoveErr) {
> * *"Error removing $SomeItem" >> $LogFile
> * *$RemoveErr >> $LogFile} else {
>
> * *"Removed $SomeItem" >> $LogFile
>
> }
>
> You can write error messages to the Event Log with:
>
> [Diagnostics.EventLog]::WriteEntry( ... )
>
> The simplest form of that is:
>
> [Diagnostics.EventLog]::WriteEntry("Source", "Message")
>
> Which adds an entry to the Application Event Log.
>
> See:
>
> http://msdn.microsoft.com/en-us/libr...ics.eventlog.w...
>
> Chris