using log4net to log to databse


New Member
I am trying to use log4net to log every thing to a mssql 2008 database. Here is what i have

DatabaseLogging.ps1 file:
$configFileInfo = gi "C:\Log4net\log4net.xml"
[log4net.GlobalContext]::Properties["timestamp"] = Get-Date -Format "yyyy-MMM-dd_hh-mm-ss"
$logger = [log4net.LogManager]::GetLogger("Test")
$logger = [log4net.LogManager]::GetLogger("PowerShell")
$logger.Info("Started the main script...$i");
$logger.Debug("This is the debugging information");
$logger.Warn("The warning is that if you try to create a file with the same name it will fail");
New-Item -ItemType file freespace.txt
New-Item -ItemType file freespace.txt 
$logger.Error("I told ya! You have an error");
$logger.Info("Exiting Test-Excp() method")
Log4net.xml File
<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=.;initial catalog=DBLog;integrated security=false;persist security info=True;User ID=sa;Password=password" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
- <parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
- <parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%thread" />
- <parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%level" />
- <parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%logger" />
- <parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%message" />
<level value="All" />
<appender-ref ref="AdoNetAppender_SqlServer" /> 
<logger name="Test" additivity="true">
So now when i execute the ps1 file it shows no error but when i check the database there is nothing in it. I really dont understand what went wrong but nothing is logged to the database. I tried the "log4net.Appender.FileAppender " it works fine, logs eveything.
Can someone please help me out with this ?
Thanks in advance.

My Computer