Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	src/Serilog.Sinks.GoogleCloudPubSub/project.json
  • Loading branch information
jose3m committed Dec 13, 2016
2 parents 1b634a4 + 86a2872 commit 921c968
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 30 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,11 @@ Log.Information("This will be sent to Google PubSub");

# Version History

- 2.0.5
If the Error/Debug file is enabled then it is registered the 'Dispose' action.

- 2.0.4
Support for NetStandard.
Support for NetStandard.
New configuration option: ErrorRetainedFileCountLimit.

- 2.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,15 @@ public void Dispose()
this._dataRollingFileSink.Dispose();
}

if (this._errorsRollingFileSink != null)
if (this._shipper != null)
{
this._errorsRollingFileSink.Dispose();
this._shipper.Dispose();
}

if (this._shipper != null)
// The errors file has to be the last one to dispose as we are using it for internal logging.
if (this._errorsRollingFileSink != null)
{
this._shipper.Dispose();
this._errorsRollingFileSink.Dispose();
}
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ internal GoogleCloudPubSubLogShipper(GoogleCloudPubSubSinkState state)
this._timer = new Timer(s => OnTick(), null, -1, -1);
#endif

#if DOTNETCORE
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += OnAppDomainUnloading;
#else
AppDomain.CurrentDomain.DomainUnload += OnAppDomainUnloading;
AppDomain.CurrentDomain.ProcessExit += OnAppDomainUnloading;
#endif
//#if DOTNETCORE
// System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += OnAppDomainUnloading;
//#else
// AppDomain.CurrentDomain.DomainUnload += OnAppDomainUnloading;
// AppDomain.CurrentDomain.ProcessExit += OnAppDomainUnloading;
//#endif

SetTimer();
}
Expand All @@ -110,17 +110,17 @@ internal GoogleCloudPubSubLogShipper(GoogleCloudPubSubSinkState state)

#region

#if DOTNETCORE
void OnAppDomainUnloading(AssemblyLoadContext assContext)
{
CloseAndFlush();
}
#else
void OnAppDomainUnloading(object sender, EventArgs args)
{
CloseAndFlush();
}
#endif
//#if DOTNETCORE
// void OnAppDomainUnloading(AssemblyLoadContext assContext)
// {
// CloseAndFlush();
// }
//#else
// void OnAppDomainUnloading(object sender, EventArgs args)
// {
// CloseAndFlush();
// }
//#endif

void CloseAndFlush()
{
Expand All @@ -132,12 +132,12 @@ void CloseAndFlush()
this._unloading = true;
}

#if DOTNETCORE
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading -= OnAppDomainUnloading;
#else
AppDomain.CurrentDomain.DomainUnload -= OnAppDomainUnloading;
AppDomain.CurrentDomain.ProcessExit -= OnAppDomainUnloading;
#endif
//#if DOTNETCORE
// System.Runtime.Loader.AssemblyLoadContext.Default.Unloading -= OnAppDomainUnloading;
//#else
// AppDomain.CurrentDomain.DomainUnload -= OnAppDomainUnloading;
// AppDomain.CurrentDomain.ProcessExit -= OnAppDomainUnloading;
//#endif

#if NO_TIMER
this._timer.Dispose();
Expand All @@ -147,9 +147,14 @@ void CloseAndFlush()
wh.WaitOne();
#endif

this._state.DebugFileAction($"{GoogleCloudPubSubLogShipper.CNST_Shipper_Debug} ******** Launching OnTick() for CloseAndFlush ... ******** ");
//---------------------
OnTick();
//---------------------
this._state.DebugFileAction($"{GoogleCloudPubSubLogShipper.CNST_Shipper_Debug} ******** CloseAndFlush FINISHED ******** ");
}


void SetTimer()
{
// Note, called under _stateLock
Expand Down Expand Up @@ -364,14 +369,19 @@ void OnTick()
// ...because we have reached the posting limit.
// ...because we have reached the size limit.
// ...because we have changed to a new buffer file.
// ...because there are more buffer files to process.
// 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;
continueWhile = ((payloadStr.Count == this._batchPostingLimit || isSizeLimitOverflow) && currentBufferFileHasMoreLines) ||
bufferFileChanged ||
this.ActionFileSetHasMoreFiles(currentFileSetPosition, fileSet);

}

}
while (continueWhile);


}
catch (Exception ex)
{
Expand Down Expand Up @@ -641,6 +651,11 @@ private void ActionInitializeCurrentFileCounters()
this.batchesSentERRORForCurrentFile = 0;
}

private bool ActionFileSetHasMoreFiles(int currentFileSetPosition, string[] fileSet)
{
return !(fileSet == null || currentFileSetPosition >= (fileSet.Count() - 1));
}

private void ActionDoRetainedFile(int currentFileSetPosition, string[] fileSet)
{
if (fileSet.Length > 1 && fileSet.Length > this._retainedFileCountLimit && currentFileSetPosition > 0)
Expand All @@ -667,6 +682,9 @@ private void _LogCurrentFile(string currentFilePath)
#endregion





//*******************************************************************
// IDisposable
//*******************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/Serilog.Sinks.GoogleCloudPubSub/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.4",
"version": "2.0.5",
"description": "The Google Cloud Pub/Sub Sink for Serilog",
"authors": [ "Oscar Pérez, XMLTravelgate CTO" ],
"packOptions": {
Expand Down

0 comments on commit 921c968

Please sign in to comment.