Trying to get log4net working with PowerShell (with a log4net config file in the mix)

Question:

I have been struggling with getting log4net working with PowerShell. I have the following PowerShell code that pulls in log4net with a configuration file and then attempts to make a simple log file entry but which errors out.

The above referenced psm_logger.psm1 file contains:

The configuration file for log4net looks like:

When run the output AND error produced is:

BEGIN: Importing module psm_logger.psm1
BEGIN: log4net configuration definition
END: log4net configuration definition
BEGIN: log4net configuration DEBUG definition
END: log4net DEBUG configuration definition
BEGIN: Module/Snapin import/addition

Method invocation failed because [System.Object[]] doesn’t contain a method named ‘Info’.
At C:\Users\Administrator\Desktop\ps\IIS\IIS_localLogs.ps1:18 char:10
+ $log.Info <<<< (“BEGIN: Module/Snapin import/addition”)
+ CategoryInfo : InvalidOperation: (Info:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Any help would be greatly appreciated!

(FYI: I originally got this code from a best practices blog entry here: http://blog.octo.com/en/powershell-v2-my-best-practices/ which I found very helpful)

Answer:

Found the solution…

The config file was corrupted by the presence of some asterisks towards the top. Removing those fixed the issue. Thank you to anybody who may have started to look at this and I hope this helps somebody else in the future.

The configuration file now looks like:

Source:

Trying to get log4net working with PowerShell (with a log4net config file in the mix) by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply