Handle tailing of files that log roll by resetting index on new file detection
This commit is contained in:
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.3.3.0")]
|
||||
[assembly: AssemblyFileVersion("1.3.3.0")]
|
||||
[assembly: AssemblyVersion("1.3.4.0")]
|
||||
[assembly: AssemblyFileVersion("1.3.4.0")]
|
||||
|
||||
@@ -69,7 +69,8 @@ namespace TimberWinR.Inputs
|
||||
recurse = _arguments.Recurse
|
||||
};
|
||||
|
||||
Dictionary<string, Int64> logFileMaxRecords = new Dictionary<string, Int64>();
|
||||
Dictionary<string, Int64> logFileMaxRecords = new Dictionary<string, Int64>();
|
||||
Dictionary<string, DateTime> logFileCreationTimes = new Dictionary<string, DateTime>();
|
||||
|
||||
// Execute the query
|
||||
while (!CancelToken.IsCancellationRequested)
|
||||
@@ -78,6 +79,9 @@ namespace TimberWinR.Inputs
|
||||
try
|
||||
{
|
||||
Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
|
||||
FileInfo fiw = new FileInfo(fileToWatch);
|
||||
if (!fiw.Exists)
|
||||
continue;
|
||||
|
||||
var qfiles = string.Format("SELECT Distinct [LogFilename] FROM {0}", fileToWatch);
|
||||
var rsfiles = oLogQuery.Execute(qfiles, iFmt);
|
||||
@@ -85,14 +89,17 @@ namespace TimberWinR.Inputs
|
||||
{
|
||||
var record = rsfiles.getRecord();
|
||||
string logName = record.getValue("LogFilename") as string;
|
||||
if (!logFileMaxRecords.ContainsKey(logName))
|
||||
FileInfo fi = new FileInfo(logName);
|
||||
DateTime creationTime = fi.CreationTimeUtc;
|
||||
if (!logFileMaxRecords.ContainsKey(logName) || (logFileCreationTimes.ContainsKey(logName) && creationTime > logFileCreationTimes[logName]))
|
||||
{
|
||||
logFileCreationTimes[logName] = creationTime;
|
||||
var qcount = string.Format("SELECT max(Index) as MaxRecordNumber FROM {0}", logName);
|
||||
var rcount = oLogQuery.Execute(qcount, iFmt);
|
||||
var qr = rcount.getRecord();
|
||||
var lrn = (Int64)qr.getValueEx("MaxRecordNumber");
|
||||
logFileMaxRecords[logName] = lrn;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (string fileName in logFileMaxRecords.Keys.ToList())
|
||||
{
|
||||
|
||||
@@ -212,6 +212,8 @@ namespace TimberWinR
|
||||
new JProperty("output", output.Name),
|
||||
new JProperty("initialized", DateTime.UtcNow)
|
||||
)));
|
||||
json.Add(new JProperty("type", "Win32-TimberWinR"));
|
||||
json.Add(new JProperty("host", computerName));
|
||||
output.Startup(json);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user