I'm trying to use log4net in my C# console application. I'm not too sure how this is used with stored procedures. With the configuration info below, how exactly will doing something like log.Info("message here")
execute the stored procedure with parameters if all I pass is the message string?
I'm using SQL Server Express as database. In AssemblyInfo.cs
I've added the following line:
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
From what I've found here on StackOverflow, I have the following in my app.config
:
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="AdoNetAppender" />
</root>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral" />
<connectionString value="data source=MyPC\\SQLEXPRESSPC;initial catalog=MyDBName;integrated security=false;persist security info=True;User ID=MyDBUser;Password=MyDBPassword" />
<commandText value="InsertGoogleDriveLog" />
<commandType value="StoredProcedure" />
<parameter>
<parameterName value="@user_name" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%username" />
</layout>
</parameter>
<parameter>
<parameterName value="@message_text" />
<dbType value="String" />
<size value="1024" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
</appender>
In my logger class I have the line:
log.Info("OK, here we are");
Also, I removed , PublicKeyToken=b77a5c561934e089
from the connectionType string value, as I'm not sure where this is obtained from when I copied it from the question here.