Background: We are using AdoNetAppender to log into an Oracle Database. There are 5 unit tests all of which log dummy error messages into the same table. The Logger instance is resolved by Unity and the lifetime is PerThreadLifetimeManager.
The code which logs into the database is as below
public void Error(LogInformation message, Exception exception)
{
mapLogInformationToContext(message);
Task.Factory.StartNew(() => Logger.Log(_stackBoundary, Level.Error, message, exception));
}`
And the log information is mapped to ThreadContext as shown below:
private static void mapLogInformationToContext(LogInformation message)
{
ThreadContext.Properties["LogUserName"] = message.LogUserName;
ThreadContext.Properties["LogMachineName"] = message.LogMachineName;
ThreadContext.Properties["LogType"] = message.LogType;
ThreadContext.Properties["LogCreateDate"] = message.LogCreateDate == default(DateTime) ? DateTime.Now : message.LogCreateDate;
if (message.LogPropertiesXml != null)
{
ThreadContext.Properties["LogPropertiesXml"] = message.LogPropertiesXml.Trim();
}
}
The problem which we are facing is with LogPropertiesXml. Even a well formatted Xml fails to log into the database with the Task.Factory.StartNew. If Tasking is eliminated, all 5 unit tests work. Otherwise only 1-2 tests randomly log into the database and others fail with this error
ORA-19202: Error occurred in XML processing LPX-00210: expected '<' instead of '(' Error at line 1 at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable) at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck) at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery() at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events)
What am I doing wrong here?