【发布时间】:2016-03-29 01:21:15
【问题描述】:
下面是我尝试使用实体框架将日志插入数据库的代码。如您所见,我正在使用异步委托来执行此操作。问题是这段代码驻留在类库中,连接字符串信息以及当我将实体框架 Oracle 数据访问内容添加到我的代码中时添加的任何 Nuget 包都位于此类库的 app.config 文件中。现在,当我在同一个解决方案中的另一个项目中添加对这个 .dll 的引用并尝试执行异步委托以将日志插入数据库时,我得到线程被中止的异常,我尝试了人们可能的一切(包括添加一个新的应用程序。项目中的配置文件,我指的是这个类库并在那里放置一个连接字符串)正在告诉stackoverflow和其他任何地方。但是我仍然无法摆脱这个异常。我已经在我的代码下面给出了整个堆栈调用。它在 SaveLogEntry(...) 方法内的 using 语句中抛出异常。
using (TracingEntity traceEntity = new TracingEntity())
private void WriteLineInternal(string message, string category, string componentName, string threadId,int windowsProcessId, string machineName, string exceptionThrown,string customMessage,int traceEventId, string processName, string userId)
{
loggingFunction = SaveLogEntry;
IAsyncResult obj = loggingFunction.BeginInvoke(message, category, componentName, threadId, windowsProcessId,machineName, exceptionThrown,customMessage,traceEventId,processName, userId, null, null);
}
private void SaveLogEntry(string message, string catrgory, string componentName, string threadId, int windowsProcessId, string machineName, string exceptionThrown, string customMessage, int traceEventId, string processName, string userId)
{
lock (traceLockObject)
{
try
{
using (TracingEntity traceEntity = new TracingEntity())
{
if (string.IsNullOrEmpty(ApplicationName))
{
traceEntity.INSERTTRACELOGS(message, catrgory, componentName, threadId, windowsProcessId, machineName, processName, exceptionThrown, customMessage, traceEventId, null, userId);
}
else
{
traceEntity.INSERTTRACELOGS(message, catrgory, componentName, threadId, windowsProcessId, machineName, processName, exceptionThrown, customMessage, traceEventId, ApplicationName, userId);
}
}
}
catch (Exception ex)
{
if (this.DBTraceFailed != null)
{
DBTraceFailed(ex.ToString());
}
this.WriteEntryToInternalLog(ex.ToString());
}
}
}
System.Threading.ThreadAbortException:线程被中止。 在 System.Data.Entity.Utilities.Check.NotEmpty(字符串值,字符串参数名称) 在 System.Data.Entity.DbContext..ctor(字符串名称或连接字符串) 在 C:\LOFT_Projects\LoggingAndTracingLib\LoggingAndTracingLib\TraceDBModel.Context.cs:line 21 中的 LoggingAndTracingLib.TracingEntity..ctor() 在 C:\LOFT_Projects\LoggingAndTracingLib\LoggingAndTracingLib\ 中的 LoggingAndTracingLib.CustomDBTraceListener.SaveLogEntry(字符串消息,字符串 catrgory,字符串 componentName,字符串 threadId,Int32 windowsProcessId,字符串 machineName,字符串 exceptionThrown,字符串 customMessage,Int32 traceEventId,字符串 processName,字符串 userId) CustomDBTraceListener.cs:483行
【问题讨论】:
-
能否给出内部异常的详细信息?
-
App.config 对 .dll 无效。将整个内容(不仅是连接字符串)复制到 .exe app.config 文件中。
标签: c# entity-framework