私がやろうとしていることは、行ごとにテキストファイルを取得し、行の始まりに応じて、送信するテーブルを決定することです。単語または「[」で始まる特定の行を特定のテーブルに送信するための最良の (最も効率的な) 方法を見つけるのに問題があります。これは、読み込んでいるテキスト ファイルの例です。これはログであり、例外、メッセージ、およびソースは、テキスト ファイルのどこにでも配置できます。"[" で始まる行は (LogTable) に、"Exception" で始まる行は (ExceptionTable) になりますが、すべての "Exception" は前のログ行に接続されているため、方法も探しています。 2 つを接続して、データベースでリンクできるようにします。
[2012-07-05 00:01:07,008] [INFO ] [MessageManager] [3780] () [] [Starting ProcessNewMessageEvent]
[2012-07-05 00:01:07,008] [INFO ] [MessageManager] [3780] () [] [Method: RegValue]
[2012-07-05 00:01:07,008] [DEBUG] [MessageManager] [3780] () [] [reg: InstallPath]
Exception: System.ServiceModel.EndpointNotFoundException
Message: There was no endpoint listening at that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Source: mscorlib
[2012-07-04 23:55:59,598] [INFO ] [MessageManager] [6616] () [] [Method: RegValue]
[2012-07-04 23:55:59,598] [DEBUG] [MessageManager] [6616] () [] [reg: InstallPath]
このコードはループしていません。最初のループを実行し、「grougquery」クエリの最後のセクションでキャッチされ、「for」ループ全体をループしないため、「Exception:」行に到達するとスローされます例外。私がここでやっていることよりも効率的な方法はありますか? 私が見つけていない別の方法?再度、感謝します
foreach (string s in filePaths)
{
string[] lines = System.IO.File.ReadAllLines(s);
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Contains("Exception:"))
{
var exQuery = from exMessage in lines
let logRecord = exMessage.Split(':')
select new ExTable()
{
ExlogException = logRecord[i],
ExlogMessage = logRecord[i + 1],
ExlogSource = logRecord[i + 2],
};
foreach (var item in exQuery)
{
exception ex = new exception();
ex.LogException = item.ExlogException;
ex.LogMessage = item.ExlogMessage;
ex.LogSource = item.ExlogSource;
ex.LogServerStackTrace = item.ExlogServerStackTrace;
ex.LogExRethrown = item.ExlogRethrown;
}
}
else if (lines[i].Contains("["))
{
var groupQuery = from date in lines
let logRecord = date.Split('[', ']', '(', ')')
select new OLog()
{
OlogDate = logRecord[1],
OlogLevel = logRecord[3],
OlogLogger = logRecord[5],
OlogThread = logRecord[7],
OlogProperty = logRecord[9],
OlogMethod = logRecord[11],
OlogException = logRecord[12],
};
foreach (var item in groupQuery)
{
temp temp = new temp();
temp.logDate = item.OlogDate;
temp.logLevel = item.OlogLevel;
temp.logLogger = item.OlogLogger;
temp.logThread = item.OlogThread;
temp.logProperty = item.OlogProperty;
temp.logMethod = item.OlogMethod;
temp.logException = item.OlogException;
logEntity.temps.AddObject(temp);
}
}
}
logEntity.SaveChanges();
}