Edit 2
What I have found out now is very strange. When I turn on unmanaged exception in Visual studio i get an format exception when trying
log4net.Config.XmlConfigurator.Configure(new System.Uri(config));
I have added some parameters to my insert and added more values
<commandText
value="INSERT INTO [Log]
([Message], [Name])
VALUES
(@log_level, @message)" />
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
It seems like if I remove my dbType tags in the parameter sections it goes a bit longer in my code. However, then I get a format exception when trying to log. If I remove one of the parameters (so I only insert with one value) it logs. I have tried inserting only one value at time (message or log_level) and it works fine but together it breaks.
If I only insert dummy-data directly in my config-sql it works with both values. SO it seems to be something very strange going on with log4Net.
Any idvise is appreciated!
end edit 2
Edit
After some trial and error and help I have changed the buffersize from 100 to 0. it seems to be some problem with righting to the SDF-file.
After restarting my device on my virtual machine I get a log error when my path to the sed-file is wrong. However when I get that correct a I get an error when I'm trying to log to the file stating "The remote connection to the device has been lost. PLease verify the device connection and restart debugging"
End edit
I'm trying to log some stuff to a SQL Server CE database on my WindowsCE device. When I log to a file everything goes as it should but when using an AdoNetAppender
it won't work.
My log4net.config looks like this:
<appender name="SQLCEAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="0"/>
<connectionType value="System.Data.SqlServerCe.SqlCeConnection, System.Data.SqlServerCe" />
<commandText
value="INSERT INTO [Loging2]
([Val])
VALUES
('1')" />
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true" />
<levelMin value="INFO" />
<levelMax value="INFO" />
</filter>
</appender>
<!-- Define some output appenders -->
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Log.log" />
<appendToFile value="true" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<rollingStyle value="Size" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<header type="log4net.Util.PatternString">
<conversionPattern value="[Header %property{windowsversion}]%newline" />
</header>
<footer value="[Footer] " />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true" />
<levelMin value="INFO" />
<levelMax value="INFO" />
</filter>
</appender>
<root>
<!--<level value="All" />-->
<appender-ref ref="DebugAppender" />
<appender-ref ref="RollingLogFileAppender" />
<appender-ref ref="SQLCEAppender" />
</root>
I have tried to have only the file appender and/or the sqldatabase appender active but no result. I have also striped my SQL query into a dummy insert only to rule out key/null values and so on.
And in my app.xaml.cs
(Silverlight application), I have this code only to make the configuration and to set the correct path to the .sdf
file.
var codeBase = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
var directory = Path.GetDirectoryName(codeBase);
var path = Path.Combine(directory, "log4Net.config");
log4net.Config.XmlConfigurator.Configure(new Uri(path));
var repo = LogManager.GetRepository();
var appender = repo.GetAppenders()
.FirstOrDefault(x => x.Name.Equals("SQLCEAppender")) as AdoNetAppender;
appender.ConnectionString = "Data Source=" + Path.Combine(directory, "Log.sdf;Persist Security Info=False;");
appender.ActivateOptions();
ILog log = LogManager.GetLogger(typeof (App));
log.Info("Starting application");
log.Debug("Printing debug");
I get a fine debug log (I have some more appenders in my config), and in my file. When I look at the appender object it says that it is open to database and if I modify the path to the .sdf
file to be something wrong, the appender isn't saying that the connection is fine.
What am I missing? I have also set the System.Data.SqlServerCe.dll
to be copied and I can see the dll on the device.
You have the bufferSize set to 100. The amount of characters you log, don't exceed the bufferSize. Try to set it to 0 and test whether it works.