Powershell and log4net to SQL Database

N

nicad49

Has anyone successfully used log4net to log to an SQL database? I am able to use log4net successfully when logging to console, files, eventlog, etc, however when attempting to log to the ADONetAppender, it cannot load my configuration file.

Here are the Powershell commands used to get setup:
$log4netDLL = "C:\Path\log4net.dll"
$log4netConfig = "C:\Path\log4net.config"
[Void][Reflection.Assembly]::LoadFile($log4netDLL)
[Log4Net.LogManager]::ResetConfiguration()
[Log4Net.Config.XmlConfigurator]::ConfigureAndWatch($log4netConfig)

Here is the ADONetAppender section of my config file:

<log4net>
<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Server=SERVER\INSTANCE;Database=LOG;Trusted_Connection=True;"/>
<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>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%thread" />
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%level" />
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%logger" />
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%message" />
</parameter>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="AdoNetAppender_SqlServer" />
</root>
</log4net>


This results in the following error:

log4net:ERROR XmlHierarchyConfigurator: Failed to find type [log4net.Layout.PatternLayout] set on [l
ayout]
System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
Parameter name: converterType
at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
at log4net.Util.OptionConverter.CanConvertTypeTo(Type sourceType, Type targetType)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [AdoNetAppender_SqlServer] of type [log4net.Appender.A
doNetAppender]. Reported error follows.
System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
Parameter name: converterType
at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetTy
pe, Type typeConstraint)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [AdoNetAppender_SqlServer] not found.

I have tried changing the layoutType to "log4net.Layout.RawPropertyLayout" (in the parameter section), and can get the .config file to load, however it only logs NULL values to the database.

Here is an example using the RawPropertyLayout:

<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.RawPropertyLayout" >
<key value="%logger" />
</layout>
</parameter>




Submitted via EggHeadCafe - Software Developer Portal of Choice
Sending SMTP email from within BizTalk Orchestration
http://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1716445b26bc/sending-smtp-email-from-w.aspx
 

My Computer

N

nicad49

For some reason the xml config didn't show up. I am using the config from:

http://logging.apache.org/log4net/release/sdk/log4net.Appender.AdoNetAppender.html




nicad49 wrote:

Powershell and log4net to SQL Database
09-Mar-10

Has anyone successfully used log4net to log to an SQL database? I am able to use log4net successfully when logging to console, files, eventlog, etc, however when attempting to log to the ADONetAppender, it cannot load my configuration file.

Here are the Powershell commands used to get setup:
$log4netDLL = "C:\Path\log4net.dll"
$log4netConfig = "C:\Path\log4net.config"
[Void][Reflection.Assembly]::LoadFile($log4netDLL)
[Log4Net.LogManager]::ResetConfiguration()
[Log4Net.Config.XmlConfigurator]::ConfigureAndWatch($log4netConfig)

Here is the ADONetAppender section of my config file:

<log4net>
<appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Server=SERVER\INSTANCE;Database=LOG;Trusted_Connection=True;"/>
<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>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%thread" />
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%level" />
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%logger" />
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%message" />
</parameter>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="AdoNetAppender_SqlServer" />
</root>
</log4net>


This results in the following error:

log4net:ERROR XmlHierarchyConfigurator: Failed to find type [log4net.Layout.PatternLayout] set on [l
ayout]
System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
Parameter name: converterType
at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
at log4net.Util.OptionConverter.CanConvertTypeTo(Type sourceType, Type targetType)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [AdoNetAppender_SqlServer] of type [log4net.Appender.A
doNetAppender]. Reported error follows.
System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
Parameter name: converterType
at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetTy
pe, Type typeConstraint)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR XmlHierarchyConfigurator: Appender named [AdoNetAppender_SqlServer] not found.

I have tried changing the layoutType to "log4net.Layout.RawPropertyLayout" (in the parameter section), and can get the .config file to load, however it only logs NULL values to the database.

Here is an example using the RawPropertyLayout:

<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.RawPropertyLayout" >
<key value="%logger" />
</layout>
</parameter>

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Adding WCF Service References
http://www.eggheadcafe.com/tutorials/aspnet/a1647f10-9aa4-4b0c-bbd9-dfa51a9fab8e/adding-wcf-service-refere.aspx
 

My Computer

S

stej

Have you tried limit count of parameter to only 1 and watch what
parameter causes problems?

On Mar 9, 7:08 pm, nicad49 wrote:

> Has anyone successfully used log4net to log to an SQL database?  I am able to use log4net successfully when logging to console, files, eventlog, etc, however when attempting to log to the ADONetAppender, it cannot load myconfiguration file.
>
> Here are the Powershell commands used to get setup:
> $log4netDLL = "C:\Path\log4net.dll"
> $log4netConfig = "C:\Path\log4net.config"
> [Void][Reflection.Assembly]::LoadFile($log4netDLL)
> [Log4Net.LogManager]::ResetConfiguration()
> [Log4Net.Config.XmlConfigurator]::ConfigureAndWatch($log4netConfig)
>
> Here is the ADONetAppender section of my config file:
>
> <log4net>
>   <appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
>     <bufferSize value="1" />
>     <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
>     <connectionString value="Server=SERVER\INSTANCE;Database=LOG;Trusted_Connection=True;"/>
>     <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>
>     <parameter>
>       <parameterName value="@thread" />
>       <dbType value="String" />
>       <size value="255" />
>       <layout type="log4net.Layout.PatternLayout" value="%thread" />
>     </parameter>
>     <parameter>
>       <parameterName value="@log_level" />
>       <dbType value="String" />
>       <size value="50" />
>       <layout type="log4net.Layout.PatternLayout" value="%level" />
>     </parameter>
>     <parameter>
>       <parameterName value="@logger" />
>       <dbType value="String" />
>       <size value="255" />
>       <layout type="log4net.Layout.PatternLayout" value="%logger" />
>     </parameter>
>     <parameter>
>       <parameterName value="@message" />
>       <dbType value="String" />
>       <size value="4000" />
>       <layout type="log4net.Layout.PatternLayout" value="%message" />
>     </parameter>
>   </appender>
>   <root>
>     <level value="DEBUG" />
>     <appender-ref ref="AdoNetAppender_SqlServer" />
>   </root>
> </log4net>
>
> This results in the following error:
>
> log4net:ERROR XmlHierarchyConfigurator: Failed to find type [log4net.Layout.PatternLayout] set on [l
> ayout]
> System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
> Parameter name: converterType
>    at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
>    at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
>    at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
>    at log4net.Util.OptionConverter.CanConvertTypeTo(Type sourceType, Type targetType)
>    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [AdoNetAppender_SqlServer] of type [log4net.Appender.A
> doNetAppender]. Reported error follows.
> System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
> Parameter name: converterType
>    at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
>    at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
>    at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
>    at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
>    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
>    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
>    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetTy
> pe, Type typeConstraint)
>    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
>    at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
> log4net:ERROR XmlHierarchyConfigurator: Appender named [AdoNetAppender_SqlServer] not found.
>
> I have tried changing the layoutType to "log4net.Layout.RawPropertyLayout" (in the parameter section), and can get the .config file to load, howeverit only logs NULL values to the database.
>
> Here is an example using the RawPropertyLayout:
>
> <parameter>
>   <parameterName value="@logger" />
>   <dbType value="String" />
>   <size value="255" />
>   <layout type="log4net.Layout.RawPropertyLayout" >
>     <key value="%logger" />
>   </layout>
> </parameter>
>
> Submitted via EggHeadCafe - Software Developer Portal of Choice
> Sending SMTP email from within BizTalk Orchestrationhttp://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1...
 

My Computer

N

nicad49

Any of the parameters using the PatternLayout seem to fail.

"stej" wrote:

> Have you tried limit count of parameter to only 1 and watch what
> parameter causes problems?
>
> On Mar 9, 7:08 pm, nicad49 wrote:

> > Has anyone successfully used log4net to log to an SQL database? I am able to use log4net successfully when logging to console, files, eventlog, etc, however when attempting to log to the ADONetAppender, it cannot load my configuration file.
> >
> > Here are the Powershell commands used to get setup:
> > $log4netDLL = "C:\Path\log4net.dll"
> > $log4netConfig = "C:\Path\log4net.config"
> > [Void][Reflection.Assembly]::LoadFile($log4netDLL)
> > [Log4Net.LogManager]::ResetConfiguration()
> > [Log4Net.Config.XmlConfigurator]::ConfigureAndWatch($log4netConfig)
> >
> > Here is the ADONetAppender section of my config file:
> >
> > <log4net>
> > <appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
> > <bufferSize value="1" />
> > <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
> > <connectionString value="Server=SERVER\INSTANCE;Database=LOG;Trusted_Connection=True;"/>
> > <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>
> > <parameter>
> > <parameterName value="@thread" />
> > <dbType value="String" />
> > <size value="255" />
> > <layout type="log4net.Layout.PatternLayout" value="%thread" />
> > </parameter>
> > <parameter>
> > <parameterName value="@log_level" />
> > <dbType value="String" />
> > <size value="50" />
> > <layout type="log4net.Layout.PatternLayout" value="%level" />
> > </parameter>
> > <parameter>
> > <parameterName value="@logger" />
> > <dbType value="String" />
> > <size value="255" />
> > <layout type="log4net.Layout.PatternLayout" value="%logger" />
> > </parameter>
> > <parameter>
> > <parameterName value="@message" />
> > <dbType value="String" />
> > <size value="4000" />
> > <layout type="log4net.Layout.PatternLayout" value="%message" />
> > </parameter>
> > </appender>
> > <root>
> > <level value="DEBUG" />
> > <appender-ref ref="AdoNetAppender_SqlServer" />
> > </root>
> > </log4net>
> >
> > This results in the following error:
> >
> > log4net:ERROR XmlHierarchyConfigurator: Failed to find type [log4net.Layout.PatternLayout] set on [l
> > ayout]
> > System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
> > Parameter name: converterType
> > at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
> > at log4net.Util.OptionConverter.CanConvertTypeTo(Type sourceType, Type targetType)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> > log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [AdoNetAppender_SqlServer] of type [log4net.Appender.A
> > doNetAppender]. Reported error follows.
> > System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
> > Parameter name: converterType
> > at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
> > at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetTy
> > pe, Type typeConstraint)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
> > log4net:ERROR XmlHierarchyConfigurator: Appender named [AdoNetAppender_SqlServer] not found.
> >
> > I have tried changing the layoutType to "log4net.Layout.RawPropertyLayout" (in the parameter section), and can get the .config file to load, however it only logs NULL values to the database.
> >
> > Here is an example using the RawPropertyLayout:
> >
> > <parameter>
> > <parameterName value="@logger" />
> > <dbType value="String" />
> > <size value="255" />
> > <layout type="log4net.Layout.RawPropertyLayout" >
> > <key value="%logger" />
> > </layout>
> > </parameter>
> >
> > Submitted via EggHeadCafe - Software Developer Portal of Choice
> > Sending SMTP email from within BizTalk Orchestrationhttp://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1...
>
> .
>
 

My Computer

N

nicad49

I should also add that if I change the first parameter (for date) to:

<layout type="log4net.Layout.RawTimeStampLayout" />

that works (if I restrict it to only that pattern).

Also, if I use the above for datetime, and then set the rest of the
parameters to use:

<layout type="log4net.Layout.RawPropertyLayout" >
<key value="Message">

the .config file loads, but it only logs null entries to the database (aside
from the date). I have used the following as values:

%message
%m
RenderedMessage
%RenderedMessage
Message

but everything logs NULL to the database.

"stej" wrote:

> Have you tried limit count of parameter to only 1 and watch what
> parameter causes problems?
>
> On Mar 9, 7:08 pm, nicad49 wrote:

> > Has anyone successfully used log4net to log to an SQL database? I am able to use log4net successfully when logging to console, files, eventlog, etc, however when attempting to log to the ADONetAppender, it cannot load my configuration file.
> >
> > Here are the Powershell commands used to get setup:
> > $log4netDLL = "C:\Path\log4net.dll"
> > $log4netConfig = "C:\Path\log4net.config"
> > [Void][Reflection.Assembly]::LoadFile($log4netDLL)
> > [Log4Net.LogManager]::ResetConfiguration()
> > [Log4Net.Config.XmlConfigurator]::ConfigureAndWatch($log4netConfig)
> >
> > Here is the ADONetAppender section of my config file:
> >
> > <log4net>
> > <appender name="AdoNetAppender_SqlServer" type="log4net.Appender.AdoNetAppender">
> > <bufferSize value="1" />
> > <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
> > <connectionString value="Server=SERVER\INSTANCE;Database=LOG;Trusted_Connection=True;"/>
> > <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>
> > <parameter>
> > <parameterName value="@thread" />
> > <dbType value="String" />
> > <size value="255" />
> > <layout type="log4net.Layout.PatternLayout" value="%thread" />
> > </parameter>
> > <parameter>
> > <parameterName value="@log_level" />
> > <dbType value="String" />
> > <size value="50" />
> > <layout type="log4net.Layout.PatternLayout" value="%level" />
> > </parameter>
> > <parameter>
> > <parameterName value="@logger" />
> > <dbType value="String" />
> > <size value="255" />
> > <layout type="log4net.Layout.PatternLayout" value="%logger" />
> > </parameter>
> > <parameter>
> > <parameterName value="@message" />
> > <dbType value="String" />
> > <size value="4000" />
> > <layout type="log4net.Layout.PatternLayout" value="%message" />
> > </parameter>
> > </appender>
> > <root>
> > <level value="DEBUG" />
> > <appender-ref ref="AdoNetAppender_SqlServer" />
> > </root>
> > </log4net>
> >
> > This results in the following error:
> >
> > log4net:ERROR XmlHierarchyConfigurator: Failed to find type [log4net.Layout.PatternLayout] set on [l
> > ayout]
> > System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
> > Parameter name: converterType
> > at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
> > at log4net.Util.OptionConverter.CanConvertTypeTo(Type sourceType, Type targetType)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> > log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [AdoNetAppender_SqlServer] of type [log4net.Appender.A
> > doNetAppender]. Reported error follows.
> > System.ArgumentNullException: CreateConverterInstance cannot create instance, converterType is null
> > Parameter name: converterType
> > at log4net.Util.TypeConverters.ConverterRegistry.CreateConverterInstance(Type converterType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConverterFromAttribute(Type destinationType)
> > at log4net.Util.TypeConverters.ConverterRegistry.GetConvertFrom(Type destinationType)
> > at log4net.Util.OptionConverter.ConvertStringTo(Type target, String txt)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ConvertStringTo(Type type, String value)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetTy
> > pe, Type typeConstraint)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
> > at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
> > log4net:ERROR XmlHierarchyConfigurator: Appender named [AdoNetAppender_SqlServer] not found.
> >
> > I have tried changing the layoutType to "log4net.Layout.RawPropertyLayout" (in the parameter section), and can get the .config file to load, however it only logs NULL values to the database.
> >
> > Here is an example using the RawPropertyLayout:
> >
> > <parameter>
> > <parameterName value="@logger" />
> > <dbType value="String" />
> > <size value="255" />
> > <layout type="log4net.Layout.RawPropertyLayout" >
> > <key value="%logger" />
> > </layout>
> > </parameter>
> >
> > Submitted via EggHeadCafe - Software Developer Portal of Choice
> > Sending SMTP email from within BizTalk Orchestrationhttp://www.eggheadcafe.com/tutorials/aspnet/9dd0f346-baf9-4674-a50f-1...
>
> .
>
 

My Computer

S

Sachin Nair

Hi,
Have you table as it is now and then use the following.

$ErrorActionPreference = "Stop"
# load the log4net library
[void][Reflection.Assembly]::LoadFile("C:\MyLogTest\log4net.dll")

function ConfigureLog4Net([string] $LOGGING_CONNECTIONSTRING)
{
$sqlAppender = New-Object log4net.Appender.AdoNetAppender
$sqlAppender.ConnectionType = "System.Data.SqlClient.SqlConnection,
System.Data,Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
$sqlAppender.ConnectionString = $LOGGING_CONNECTIONSTRING
$sqlAppender.CommandText = "INSERT INTO
MyLogs([Date],[Thread],[Level],[Logger],[Message],[Exception])
VALUES(@log_date, @thread, @log_level, @logger, @message,@exception)"

$param1 = New-Object log4net.Appender.AdoNetAppenderParameter
$param1.ParameterName = "@log_date"
$param1.Layout = New-Object log4net.Layout.RawTimeStampLayout
$param1.DbType = "DateTime"
$sqlAppender.AddParameter($param1)

$param2 = New-Object log4net.Appender.AdoNetAppenderParameter
$param2.ParameterName = "@log_level"
$parm2Layout=New-Object log4net.Layout.PatternLayout("%level")
$param2.Layout = New-Object
log4net.Layout.Layout2RawLayoutAdapter($parm2Layout)
$param2.DbType = "String"
$param2.Size = 50
$sqlAppender.AddParameter($param2)

$param3 = New-Object log4net.Appender.AdoNetAppenderParameter
$param3.ParameterName = "@thread"
$param3Layout= New-Object log4net.Layout.PatternLayout("%thread")
$param3.Layout = New-Object
log4net.Layout.Layout2RawLayoutAdapter($param3Layout)
$param3.DbType = "String"
$param3.Size = 255
$sqlAppender.AddParameter($param3)

$param4 = New-Object log4net.Appender.AdoNetAppenderParameter
$param4.ParameterName = "@logger"
$param4Layout = New-Object log4net.Layout.PatternLayout("%logger")
$param4.Layout = New-Object
log4net.Layout.Layout2RawLayoutAdapter($param4Layout)
$param4.DbType = "String"
$param4.Size = 255
$sqlAppender.AddParameter($param4)

$param5 = New-Object log4net.Appender.AdoNetAppenderParameter
$param5.ParameterName = "@message"
$param5.DbType = "String"
$param5Layout = New-Object log4net.Layout.PatternLayout("%message")
$param5.Layout = New-Object
log4net.Layout.Layout2RawLayoutAdapter($param5Layout)
$param5.Size = 4000
$sqlAppender.AddParameter($param5)

$param6 = New-Object log4net.Appender.AdoNetAppenderParameter
$param6.ParameterName = "@exception"
$param6.DbType = "String"
$param6Layout = New-Object log4net.Layout.ExceptionLayout
$param6.Layout = New-Object
log4net.Layout.Layout2RawLayoutAdapter($param6Layout)
$param6.Size = 4000
$sqlAppender.AddParameter($param6)

$sqlAppender.BufferSize = 1
$sqlAppender.ActivateOptions()

[log4net.Config.BasicConfigurator]::Configure($sqlAppender)
}

$constr="data source=nair-s1-xp;initial catalog=AppErrorLogs;integrated
security=false;persist security info=True;User ID=sa;Password=mssqlsa100"
ConfigureLog4Net "$constr"
[log4net.ILog] $logger = [log4net.LogManager]::GetLogger("MyLogs")
[log4net.Repository.Hierarchy.Logger] $l
=[log4net.Repository.Hierarchy.Logger]$logger.Logger
$l.Level = $l.Hierarchy.LevelMap["All"]
$logger.Info("Info")
$logger.Debug("Debug")
$logger.Error("Error")
$logger.Warn("Warn")
$logger.Fatal("Fatal")

Actually the problem in using the xml file is that it fails to convert the
pattern layout so i used the above code to do it manually.
thanks to
http://www.williamkent.net/archive/2007/09/04/using-log4net-inside-of-sharepoint.aspx

Enjoy ! :)
 

My Computer

Top