diff --git a/README.md b/README.md
index 81969de..ccc817b 100644
--- a/README.md
+++ b/README.md
@@ -190,6 +190,10 @@ By default just errors information is stored.
The maximum size, in bytes, to which the error/debug file for the specifier will be allowed to grow.
By default no limit will be applied.
+### ErrorRollingSpecifier
+Rolling specifier: {Date}, {Hour} or {HalfHour}.
+The default one is {Date}.
+
### ErrorStoreEvents
If set to 'true' then events related to any error will be saved to the error file (after the error message).
By default it is false.
@@ -202,6 +206,10 @@ By default it is false.
If set to 'true' then skiped events (greater than the BatchSizeLimitBytes) will be stored.
By default it is false.
+### DebugStoreFileAction
+If set to 'true' then all file actions (move forward, delete, ...) will me stored.
+By default it is false.
+
### DebugStoreAll
If set to 'true' then ALL debug data will be stored. If set to 'false' then each type of debug data will be stored depending on its own switch.
By default it is false.
@@ -290,6 +298,11 @@ Log.Information("This will be sent to Google PubSub");
```
+# Version History
+
+- 2.0.3
+Bug fix.
+New configuration options: ErrorRollingSpecifier and DebugStoreFileAction.
diff --git a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/DurableGoogleCloudPubSubSink.cs b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/DurableGoogleCloudPubSubSink.cs
index 64b7fae..e6084e5 100644
--- a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/DurableGoogleCloudPubSubSink.cs
+++ b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/DurableGoogleCloudPubSubSink.cs
@@ -96,6 +96,7 @@ public DurableGoogleCloudPubSubSink(GoogleCloudPubSubSinkOptions options)
/// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Hour}.
/// The maximum number of error log files that will be retained, including the current error file. For unlimited retention, pass null. The default is 31.
/// If set to 'true' then all file actions(move forward, delete, ...) will me stored.
+ /// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Date}.
/// LoggerConfiguration object
/// is .
/// is .
@@ -123,7 +124,8 @@ public DurableGoogleCloudPubSubSink(
bool? debugStoreEventSkip = null,
string bufferRollingSpecifier = null,
int? errorRetainedFileCountLimit = null,
- bool? debugStoreFileAction = null)
+ bool? debugStoreFileAction = null,
+ string errorRollingSpecifier = null)
{
//--- Creating an options object with the received parameters -------------
@@ -151,7 +153,8 @@ public DurableGoogleCloudPubSubSink(
debugStoreEventSkip,
bufferRollingSpecifier,
errorRetainedFileCountLimit,
- debugStoreFileAction);
+ debugStoreFileAction,
+ errorRollingSpecifier);
//-----
@@ -178,7 +181,7 @@ private void Initialize(GoogleCloudPubSubSinkOptions options)
if (!string.IsNullOrWhiteSpace(options.ErrorBaseFilename))
{
this._errorsRollingFileSink = new RollingFileSink(
- options.ErrorBaseFilename + CNST_Specifier_Separator + options.BufferRollingSpecifier + errorsFileExtension,
+ options.ErrorBaseFilename + CNST_Specifier_Separator + options.ErrorRollingSpecifier + errorsFileExtension,
new GoogleCloudPubSubRawFormatter(), // Formatter for error info (raw).
options.ErrorFileSizeLimitBytes,
options.ErrorRetainedFileCountLimit
diff --git a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubLogShipper.cs b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubLogShipper.cs
index 5b5211f..7600acb 100644
--- a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubLogShipper.cs
+++ b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubLogShipper.cs
@@ -50,9 +50,13 @@ class GoogleCloudPubSubLogShipper : IDisposable
private static readonly int CNST_NewLineBytes = Encoding.UTF8.GetByteCount(Environment.NewLine);
- // Stats for current file.
- private int linesSentForCurrentFile = 0;
- private int batchsSentForCurrentFile = 0;
+ // Stats for current file (to store when it is finished).
+ private int linesSentOKForCurrentFile = 0;
+ private int linesSentERRORForCurrentFile = 0;
+ private int linesDroppedForCurrentFile = 0;
+ private int overflowsForCurrentFile = 0;
+ private int batchesSentOKForCurrentFile = 0;
+ private int batchesSentERRORForCurrentFile = 0;
#endregion
@@ -131,24 +135,23 @@ void SetTimer()
#region
void OnTick()
{
- try
+ string currentFilePath = null;
+
+ try
{
- var count = 0;
- bool isSizeLimitOverflow = false;
- bool hasMoreLines = true;
+ bool continueWhile = false;
do
{
// Locking the bookmark ensures that though there may be multiple instances of this
// class running, only one will ship logs at a time.
- using (var bookmark = System.IO.File.Open(this._bookmarkFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read))
+ using (FileStream bookmark = System.IO.File.Open(this._bookmarkFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read))
{
- string auxMessage = null;
//--- 1st step : identify the current buffer file and position to read from --------------------------------------------
long nextLineBeginsAtOffset; // Current position to read in the current buffer file.
- string currentFilePath; // Current buffer file path with data to read and send.
+ currentFilePath = null; // Current buffer file path with data to read and send.
// NOTE:
// Data is recovered from one buffer file each time onTick is executed.
@@ -157,7 +160,7 @@ void OnTick()
GoogleCloudPubSubLogShipper.TryReadBookmark(bookmark, out nextLineBeginsAtOffset, out currentFilePath);
// Candidate buffer files (in the working folder): all and ordered by name to have a sequence of treatment.
- string[] fileSet = this.GetFileSet();
+ string[] fileSet = GoogleCloudPubSubLogShipper.GetFileSet(this._logFolder, this._candidateSearchPath);
// We don't have a bookmark or it is not pointing to an existing file...
if (currentFilePath == null || !System.IO.File.Exists(currentFilePath))
@@ -172,7 +175,7 @@ void OnTick()
// Position of the current file in the set.
int currentFileSetPosition = 0;
- if (!this.GetFileSetPosition(fileSet, currentFilePath, out currentFileSetPosition))
+ if (!GoogleCloudPubSubLogShipper.GetFileSetPosition(fileSet, currentFilePath, out currentFileSetPosition))
{
this._state.Error($"The current file (bookmark) does not exist in the file set and I don't know what to do. [{currentFilePath}]");
continue; // >>>>>>>>>>>>>
@@ -182,29 +185,29 @@ void OnTick()
// All files that match the template (that are contained in the FileSet) will be considered and managed.
- //--- 2nd step : read current buffer file and position ------------------------------------------------------
+ //--- 2nd step : read current buffer file from starting position ------------------------------------------------------
List payloadStr = new List();
long payloadSizeByte = 0;
- count = 0;
- isSizeLimitOverflow = false;
- hasMoreLines = true;
+ bool isSizeLimitOverflow = false;
+ bool currentBufferFileHasMoreLines = true;
+ bool bufferFileChanged = false;
- using (var current = System.IO.File.Open(currentFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ using (FileStream currentBufferFile = System.IO.File.Open(currentFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
- current.Position = nextLineBeginsAtOffset;
+ currentBufferFile.Position = nextLineBeginsAtOffset;
string nextLine;
long nextlineSizeByte;
bool continueAdding = true;
- long previousBeginsAtOffset;
+ long previousLineBeginsAtOffset;
- while (count < this._batchPostingLimit && continueAdding && hasMoreLines)
+ while (payloadStr.Count < this._batchPostingLimit && continueAdding && currentBufferFileHasMoreLines)
{
- previousBeginsAtOffset = nextLineBeginsAtOffset;
+ previousLineBeginsAtOffset = nextLineBeginsAtOffset;
// Is there a next line to send? ...
- if (GoogleCloudPubSubLogShipper.TryReadLine(current, ref nextLineBeginsAtOffset, out nextLine, out nextlineSizeByte))
+ if (GoogleCloudPubSubLogShipper.TryReadLine(currentBufferFile, ref nextLineBeginsAtOffset, out nextLine, out nextlineSizeByte))
{
// Is there space enough to send the next line in this batch? ...
@@ -212,9 +215,7 @@ void OnTick()
(payloadSizeByte + nextlineSizeByte <= this._batchSizeLimitBytes.Value))
{
//---The next line is added ------------------
- payloadSizeByte += nextlineSizeByte;
- payloadStr.Add(nextLine);
- ++count;
+ this.ActionAddLineToPayload(payloadStr, ref payloadSizeByte, nextLine, nextlineSizeByte);
//--------------------------------------------
}
else
@@ -227,10 +228,7 @@ void OnTick()
{
// If the line is bigger than the max size for the batch then it is skipped and an error is saved (this
// line will never be sent and would stop sending following lines in an infinite bucle).
- auxMessage = $"{CNST_Shipper_Error} Line skipped because it is bigger ({nextlineSizeByte}) than BatchSizeLimitBytes ({this._batchSizeLimitBytes.Value}).";
- SelfLog.WriteLine(auxMessage);
- this._state.Error(auxMessage);
- this._state.DebugEventSkip(CNST_Shipper_Debug, nextLine);
+ this.ActionSkipLine(nextLine, nextlineSizeByte);
}
catch
{
@@ -240,16 +238,15 @@ void OnTick()
{
// The line has to be processed with the next batch, so we modify the offset to be stored with the mark
// if the current batch data is sent correctly.
- continueAdding = false;
- nextLineBeginsAtOffset = previousBeginsAtOffset;
+ this.ActionMoveLineBackwards(ref continueAdding, ref nextLineBeginsAtOffset, previousLineBeginsAtOffset);
}
}
}
else
{
- // There is no more data to add to this batch.
- hasMoreLines = false;
+ // There is no more data to add to this batch for the current file.
+ currentBufferFileHasMoreLines = false;
}
} //---end:while---
@@ -257,22 +254,23 @@ void OnTick()
}
- if (count == this._batchPostingLimit || isSizeLimitOverflow)
+ if (payloadStr.Count == this._batchPostingLimit || isSizeLimitOverflow)
{
// ...we have reached the posting limit.
// ...we have reached the size limit.
- this._state.DebugOverflow(CNST_Shipper_Debug, count, this._batchPostingLimit, payloadSizeByte, this._batchSizeLimitBytes);
+ this._state.DebugOverflow(CNST_Shipper_Debug, payloadStr.Count, this._batchPostingLimit, payloadSizeByte, this._batchSizeLimitBytes);
+ this.overflowsForCurrentFile++;
}
//--- 3rd step : send data (if we have any) and update bookmark ------------------------------------------------------
// Do we have data to send?
- if (count > 0)
+ if (payloadStr.Count > 0)
{
// ...yes, we have data, so come on...
- this._state.Debug($"{CNST_Shipper_Debug} Payload to send ({count} lines, {payloadSizeByte} bytes)...", payloadStr);
+ this._state.Debug($"{GoogleCloudPubSubLogShipper.CNST_Shipper_Debug} Payload to send ({payloadStr.Count} lines, {payloadSizeByte} bytes)...", payloadStr);
//--- Sending data to Google PubSub... ------------
GoogleCloudPubSubClientResponse response = this._state.Publish(payloadStr);
@@ -281,21 +279,16 @@ void OnTick()
if (response.Success)
{
//--- OK ---
- GoogleCloudPubSubLogShipper.WriteBookmark(bookmark, nextLineBeginsAtOffset, currentFilePath);
- this._connectionSchedule.MarkSuccess();
- this.linesSentForCurrentFile += payloadStr.Count;
- this.batchsSentForCurrentFile++;
- //---
- this._state.Debug($"{CNST_Shipper_Debug} OK sending data to PubSub.");
+ this.ActionMarkBatchSentOK(bookmark, nextLineBeginsAtOffset, currentFilePath, payloadStr);
}
else
{
//--- ERROR ---
- this._connectionSchedule.MarkFailure();
- //---
- auxMessage = $"{CNST_Shipper_Error} ERROR sending data to PubSub. [{response.ErrorMessage}]";
- SelfLog.WriteLine(auxMessage);
- this._state.Error(auxMessage, payloadStr);
+ this.ActionMarkBatchSentERROR(response.ErrorMessage, payloadStr);
+
+ // The while bucle is broken and we will exit the current tick.
+ // The scheduler will se that there has been an error so will act taking it in mind
+ // when calculating next tick.
break;
}
@@ -307,8 +300,7 @@ void OnTick()
// We don't have sent anything to PubSub but an overflow has been detected. This means that there was almost
// one line to send and all were bigger than the size limit.
// In this case we have to update the bookmark too: if not then next tick will start with this same big line.
- GoogleCloudPubSubLogShipper.WriteBookmark(bookmark, nextLineBeginsAtOffset, currentFilePath);
- this._connectionSchedule.MarkSuccess();
+ this.ActionMarkNoBatchButGoForward(bookmark, nextLineBeginsAtOffset, currentFilePath);
}
else
{
@@ -316,50 +308,32 @@ void OnTick()
// For whatever reason, there's nothing waiting to send. This means we should try connecting again at the
// regular interval, so mark the attempt as successful.
- this._connectionSchedule.MarkSuccess();
+ this.ActionMarkNoBatchButSuccess();
// Only advance the bookmark if no other process has the current file locked, and its length is as we found it
// and there is another next file.
- int nextFileSetPosition = currentFileSetPosition + 1;
- if (nextFileSetPosition < fileSet.Length && IsUnlockedAtLength(currentFilePath, nextLineBeginsAtOffset, this._state))
- {
- // --- Move to next file --------------------------------------------------
- this._state.DebugFileAction($"{CNST_Shipper_Debug} File finished: Lines=[{this.linesSentForCurrentFile}] Batchs=[{this.batchsSentForCurrentFile}] File=[{currentFilePath}]");
- this._state.DebugFileAction($"{CNST_Shipper_Debug} Move forward to next file. [{fileSet[nextFileSetPosition]}].");
- GoogleCloudPubSubLogShipper.WriteBookmark(bookmark, 0, fileSet[nextFileSetPosition]);
- this.linesSentForCurrentFile = 0;
- this.batchsSentForCurrentFile = 0;
- //-------------------------------------------------------------------------
- }
-
- //if (fileSet.Length > 2)
- //{
- // // Once there's a third file waiting to ship, we do our
- // // best to move on, though a lock on the current file
- // // will delay this.
-
- // System.IO.File.Delete(fileSet[0]);
- //}
+ bufferFileChanged = this.ActionGoToNextBufferFileIfAny(bookmark, currentFilePath, currentFileSetPosition, nextLineBeginsAtOffset, fileSet);
}
-
+
//--- Retained File Count Limit --------------
// If necessary, one obsolete file is deleted each time.
// It is done even there is or not data to send: it is possible that our application is sending data at any time.
- if (fileSet.Length > 2 && fileSet.Length > this._retainedFileCountLimit && currentFileSetPosition > 0)
- {
- this._state.DebugFileAction($"{CNST_Shipper_Debug} File delete. [{fileSet[0]}].");
- System.IO.File.Delete(fileSet[0]);
- }
+ this.ActionDoRetainedFile(currentFileSetPosition, fileSet);
//--------------------------------------------
+ // Batch data sent will be done while it is supposed to be more data to send...
+ // ...because we have reached the posting limit.
+ // ...because we have reached the size limit.
+ // ...because we have changed to a new buffer file.
+ // If we go forward with current file but it hasn't got more lines then nothing wrong happens: next iteration will
+ // dtect that it hasn't got more information and it will produce to look for a next buffer file.
+ continueWhile = ((payloadStr.Count == this._batchPostingLimit || isSizeLimitOverflow) && currentBufferFileHasMoreLines) || bufferFileChanged;
+
}
}
- while ((count == this._batchPostingLimit || isSizeLimitOverflow) && hasMoreLines);
- // Batch data sent will be done while it is supposed to be more data to send...
- // ...because we have reached the posting limit.
- // ...because we have reached the size limit.
+ while (continueWhile);
}
catch (Exception ex)
@@ -374,7 +348,17 @@ void OnTick()
{
lock (this._stateLock)
{
- if (!this._unloading)
+ if (this._unloading)
+ {
+ try
+ {
+ this._LogCurrentFile(currentFilePath);
+ }
+ catch (Exception)
+ {
+ }
+ }
+ else
{
SetTimer();
}
@@ -387,7 +371,7 @@ void OnTick()
//*******************************************************************
- // FILES MANAGEMENT FUNCTIONS
+ // FILES MANAGEMENT FUNCTIONS (static)
//*******************************************************************
#region
@@ -421,14 +405,6 @@ static bool IsUnlockedAtLength(string file, long maxLen, GoogleCloudPubSubSinkSt
return false;
}
- static void WriteBookmark(FileStream bookmark, long nextLineBeginsAtOffset, string currentFile)
- {
- using (var writer = new StreamWriter(bookmark))
- {
- writer.WriteLine("{0}:::{1}", nextLineBeginsAtOffset, currentFile);
- }
- }
-
static bool TryReadLine(Stream current, ref long nextStart, out string nextLine, out long nextlineSizeByte)
{
//bool includesBom = (nextStart == 0);
@@ -458,7 +434,42 @@ static bool TryReadLine(Stream current, ref long nextStart, out string nextLine,
return true;
}
+ static string[] GetFileSet(string logFolder, string candidateSearchPath)
+ {
+ return Directory.GetFiles(logFolder, candidateSearchPath)
+ .OrderBy(n => n)
+ .ToArray();
+ }
+ static bool GetFileSetPosition(string[] fileSet, string filePath, out int fileSetPosition)
+ {
+ fileSetPosition = 0;
+
+ if (fileSet != null)
+ {
+ foreach (string f in fileSet)
+ {
+ if (fileSet[fileSetPosition] == filePath)
+ {
+ return true;
+ }
+
+ fileSetPosition++;
+ }
+ }
+
+ return false;
+ }
+
+ #endregion
+
+
+
+ //*******************************************************************
+ // BOOKMARK MANAGEMENT (static)
+ //*******************************************************************
+
+ #region
static void TryReadBookmark(Stream bookmark, out long nextLineBeginsAtOffset, out string currentFile)
{
nextLineBeginsAtOffset = 0;
@@ -486,35 +497,137 @@ static void TryReadBookmark(Stream bookmark, out long nextLineBeginsAtOffset, ou
}
}
- string[] GetFileSet()
+ static void WriteBookmark(FileStream bookmark, long nextLineBeginsAtOffset, string currentFile)
{
- return Directory.GetFiles(this._logFolder, this._candidateSearchPath)
- .OrderBy(n => n)
- .ToArray();
+ using (var writer = new StreamWriter(bookmark))
+ {
+ writer.WriteLine("{0}:::{1}", nextLineBeginsAtOffset, currentFile);
+ }
}
- bool GetFileSetPosition(string[] fileSet, string filePath, out int fileSetPosition)
+ #endregion
+
+
+ //*******************************************************************
+ // SUB-ACTIONS
+ //*******************************************************************
+
+ #region
+
+ private void ActionAddLineToPayload(List payloadStr, ref long payloadSizeByte, string nextLine, long nextlineSizeByte)
{
- fileSetPosition = 0;
+ payloadStr.Add(nextLine);
+ payloadSizeByte += nextlineSizeByte;
+ }
- if (fileSet != null)
+ private void ActionSkipLine(string nextLine, long nextlineSizeByte)
+ {
+ string auxMessage = $"{GoogleCloudPubSubLogShipper.CNST_Shipper_Error} Line skipped because it is bigger ({nextlineSizeByte}) than BatchSizeLimitBytes ({this._batchSizeLimitBytes.Value}).";
+ SelfLog.WriteLine(auxMessage);
+ this._state.Error(auxMessage);
+ this._state.DebugEventSkip(GoogleCloudPubSubLogShipper.CNST_Shipper_Debug, nextLine);
+ this.linesDroppedForCurrentFile++;
+ }
+
+ private void ActionMoveLineBackwards(ref bool continueAdding, ref long nextLineBeginsAtOffset, long previousBeginsAtOffset)
+ {
+ continueAdding = false;
+ nextLineBeginsAtOffset = previousBeginsAtOffset;
+ }
+
+ private void ActionMarkBatchSentOK(FileStream bookmark, long nextLineBeginsAtOffset, string currentFilePath, List payloadStr)
+ {
+ GoogleCloudPubSubLogShipper.WriteBookmark(bookmark, nextLineBeginsAtOffset, currentFilePath);
+ this._connectionSchedule.MarkSuccess();
+ //---
+ this._state.Debug($"{GoogleCloudPubSubLogShipper.CNST_Shipper_Debug} OK sending data to PubSub.");
+ //---
+ this.linesSentOKForCurrentFile += payloadStr.Count;
+ this.batchesSentOKForCurrentFile++;
+ }
+
+ private void ActionMarkBatchSentERROR(string errorMessage, List payloadStr)
+ {
+ this._connectionSchedule.MarkFailure();
+ //--
+ string auxMessage = $"{GoogleCloudPubSubLogShipper.CNST_Shipper_Error} ERROR sending data to PubSub. [{errorMessage}]";
+ SelfLog.WriteLine(auxMessage);
+ this._state.Error(auxMessage, payloadStr);
+ //---
+ this.linesSentERRORForCurrentFile += payloadStr.Count;
+ this.batchesSentERRORForCurrentFile++;
+ }
+
+ private void ActionMarkNoBatchButGoForward(FileStream bookmark, long nextLineBeginsAtOffset, string currentFilePath)
+ {
+ GoogleCloudPubSubLogShipper.WriteBookmark(bookmark, nextLineBeginsAtOffset, currentFilePath);
+ this._connectionSchedule.MarkSuccess();
+ }
+
+ private void ActionMarkNoBatchButSuccess()
+ {
+ this._connectionSchedule.MarkSuccess();
+ }
+
+ private bool ActionGoToNextBufferFileIfAny(FileStream bookmark, string currentFilePath, int currentFileSetPosition, long nextLineBeginsAtOffset, string[] fileSet)
+ {
+ int nextFileSetPosition = currentFileSetPosition + 1;
+ if (nextFileSetPosition < fileSet.Length && GoogleCloudPubSubLogShipper.IsUnlockedAtLength(currentFilePath, nextLineBeginsAtOffset, this._state))
{
- foreach (string f in fileSet)
- {
- if (fileSet[fileSetPosition] == filePath)
- {
- return true;
- }
+ // --- Move to next file --------------------------------------------------
- fileSetPosition++;
+ try
+ {
+ this._LogCurrentFile(currentFilePath);
+ this._state.DebugFileAction($"{GoogleCloudPubSubLogShipper.CNST_Shipper_Debug} Move forward to next file. [{fileSet[nextFileSetPosition]}].");
}
+ catch (Exception)
+ {
+ }
+
+ GoogleCloudPubSubLogShipper.WriteBookmark(bookmark, 0, fileSet[nextFileSetPosition]);
+ //---
+ this.ActionInitializeCurrentFileCounters();
+ //---
+ return true; //We force to manage the new file immediately.
}
+ return false; //We continue with the same buffer file.
+ }
- return false;
+ private void ActionInitializeCurrentFileCounters()
+ {
+ this.linesSentOKForCurrentFile = 0;
+ this.linesSentERRORForCurrentFile = 0;
+ this.linesDroppedForCurrentFile = 0;
+ this.overflowsForCurrentFile = 0;
+ this.batchesSentOKForCurrentFile = 0;
+ this.batchesSentERRORForCurrentFile = 0;
}
- #endregion
+ private void ActionDoRetainedFile(int currentFileSetPosition, string[] fileSet)
+ {
+ if (fileSet.Length > 1 && fileSet.Length > this._retainedFileCountLimit && currentFileSetPosition > 0)
+ {
+ this._state.DebugFileAction($"{GoogleCloudPubSubLogShipper.CNST_Shipper_Debug} File delete. [{fileSet[0]}].");
+ System.IO.File.Delete(fileSet[0]);
+ }
+ }
+ private void _LogCurrentFile(string currentFilePath)
+ {
+ string auxMessage = string.Format("{0} File finished: LinesOK=[{1}] LinesERROR=[{2}] LinesSkiped=[{3}] BatchesOK=[{4}] BatchesERROR=[{5}] Overflows=[{6}] File=[{7}]",
+ GoogleCloudPubSubLogShipper.CNST_Shipper_Debug,
+ this.linesSentOKForCurrentFile,
+ this.linesSentERRORForCurrentFile,
+ this.linesDroppedForCurrentFile,
+ this.batchesSentOKForCurrentFile,
+ this.batchesSentERRORForCurrentFile,
+ this.overflowsForCurrentFile,
+ currentFilePath
+ );
+ this._state.DebugFileAction(auxMessage);
+ }
+ #endregion
//*******************************************************************
diff --git a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubSinkOptions.cs b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubSinkOptions.cs
index 8ae26d5..b50adaa 100644
--- a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubSinkOptions.cs
+++ b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/GoogleCloudPubSub/GoogleCloudPubSubSinkOptions.cs
@@ -135,6 +135,11 @@ public class GoogleCloudPubSubSinkOptions
///
public long? ErrorFileSizeLimitBytes { get; set; }
+ ///
+ /// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Date}.
+ ///
+ public string ErrorRollingSpecifier { get; set; }
+
///
/// If set to 'true' then events related to any error will be saved to the error file (after the error message).
///
@@ -230,6 +235,7 @@ protected GoogleCloudPubSubSinkOptions()
this.Period = TimeSpan.FromSeconds(2);
this.MessageDataToBase64 = true;
this.BufferRollingSpecifier = "{Hour}";
+ this.ErrorRollingSpecifier = "{Date}";
this.BufferRetainedFileCountLimit = 31;
this.ErrorRetainedFileCountLimit = 31;
}
@@ -280,6 +286,7 @@ public GoogleCloudPubSubSinkOptions(string projectId, string topicId) : this()
/// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Hour}.
/// The maximum number of error log files that will be retained, including the current error file. For unlimited retention, pass null. The default is 31.
/// If set to 'true' then all file actions (move forward, delete, ...) will me stored.
+ /// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Date}.
public void SetValues(
string bufferBaseFilename,
long? bufferFileSizeLimitBytes = null,
@@ -301,7 +308,8 @@ public void SetValues(
bool? debugStoreEventSkip = null,
string bufferRollingSpecifier = null,
int? errorRetainedFileCountLimit = null,
- bool? debugStoreFileAction = null)
+ bool? debugStoreFileAction = null,
+ string errorRollingSpecifier = null)
{
this.BufferBaseFilename = bufferBaseFilename;
this.ErrorBaseFilename = errorBaseFilename;
@@ -356,6 +364,9 @@ public void SetValues(
if (debugStoreFileAction != null)
this.DebugStoreFileAction = debugStoreFileAction.Value;
+ if (!string.IsNullOrEmpty(errorRollingSpecifier))
+ this.ErrorRollingSpecifier = errorRollingSpecifier;
+
//---
if (messageDataToBase64 != null)
diff --git a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/LoggerConfigurationGoogleCloudPubSubExtensions.cs b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/LoggerConfigurationGoogleCloudPubSubExtensions.cs
index 719a9db..afbc3af 100644
--- a/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/LoggerConfigurationGoogleCloudPubSubExtensions.cs
+++ b/src/Serilog.Sinks.GoogleCloudPubSub/Sinks/LoggerConfigurationGoogleCloudPubSubExtensions.cs
@@ -66,6 +66,7 @@ public static class LoggerConfigurationGoogleCloudPubSubExtensions
/// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Hour}.
/// The maximum number of error log files that will be retained, including the current error file. For unlimited retention, pass null. The default is 31.
/// If set to 'true' then all file actions (move forward, delete, ...) will me stored.
+ /// Rolling specifier: {Date}, {Hour} or {HalfHour}. The default one is {Date}.
/// LoggerConfiguration object
/// is .
/// is .
@@ -94,7 +95,8 @@ public static LoggerConfiguration GoogleCloudPubSub(
bool? debugStoreEventSkip = null,
string bufferRollingSpecifier = null,
int? errorRetainedFileCountLimit = null,
- bool? debugStoreFileAction = null)
+ bool? debugStoreFileAction = null,
+ string errorRollingSpecifier = null)
{
//--- Creating an options object with the received parameters -------------
@@ -122,7 +124,8 @@ public static LoggerConfiguration GoogleCloudPubSub(
debugStoreEventSkip,
bufferRollingSpecifier,
errorRetainedFileCountLimit,
- debugStoreFileAction);
+ debugStoreFileAction,
+ errorRollingSpecifier);
//--- Mandatory parameters ------------
diff --git a/src/Serilog.Sinks.GoogleCloudPubSub/project.json b/src/Serilog.Sinks.GoogleCloudPubSub/project.json
index 86668ef..fc7527b 100644
--- a/src/Serilog.Sinks.GoogleCloudPubSub/project.json
+++ b/src/Serilog.Sinks.GoogleCloudPubSub/project.json
@@ -1,5 +1,5 @@
{
- "version": "2.0.2-*",
+ "version": "2.0.3-*",
"description": "The Google Cloud Pub/Sub Sink for Serilog",
"authors": ["Oscar PĂ©rez, XMLTravelgate CTO"],
"packOptions": {