以下は、Entity Frameworkを使用してデータベースにログを挿入しようとしている私のコードです。ご覧のとおり、非同期デリゲートを使用しています。このコードは、クラスライブラリと接続文字列情報内にあり、Entity FrameworkのOracleデータアクセス用のものを自分のコードに追加したときに追加したNugetパッケージは、このクラスライブラリのapp.configファイルにあります。今私は同じソリューションで私の他のプロジェクトでこの.dllへの参照を追加し、非同期デリゲートをデータベースに挿入するために非同期デリゲートを実行しようとすると、スレッドが例外を中止するようになる。私はこのクラスライブラリを参照していると同様に接続文字列を入れているプロジェクト内の設定ファイル)は、stackoverflowと他のすべてのことを教えている。しかし、まだ私はこの例外を取り除くことができません。私は、私のコードの下にスタック全体を与えました。これは、SaveLogEntry(...)メソッド内のusingステートメントで例外をスローします。EntityFrameworkを使用してデータを挿入中にスレッドが中止される
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:スレッドが中止されていました。 at System.Data.Entity.Utilities.Check.NotEmpty(文字列値、String parameterName) at System.Data.Entity.DbContext..ctor(String nameOrConnectionString) at LoggingAndTracingLib.TracingEntity..ctor()in C:\ LOFT_Projects \ LoggingAndTracingLib \ LoggingAndTracingLib \ TraceDBModel.Context.cs:Line 21 LoggingAndTracingLib.CustomDBTraceListener.SaveLogEntry(文字列メッセージ、String catrgory、String componentName、String threadId、Int32 windowsProcessId、String machineName、String exceptionThrown、String customMessage、Int32 traceEventId、String) C:\ LOFT_Projects \ LoggingAndTracingLib \ LoggingAndTracingLib \ CustomDBTraceListener.cs:line 483
内部例外の詳細を教えてもらえますか? –
App.configは.dllに影響しません。すべてのコンテンツ(接続文字列だけでなく)を.exe app.configファイルにコピーします。 –