I use an automatic transfer of Event Log on schedule (for example, every 10 minutes). My problem is the log transfer in "OnStop" method. I want logs that have not been transferred yet (to the table storage) to be copied there nevertheless. Ideally it would
be wonderful just to call a method like "Flush". But for some reason there is not such a way.
diagConfig.WindowsEventLog.DataSources.Add("Application!*[System[Provider[@Name='ASP.NET 4.0.30319.0'] and (Level=2 or Level=3)]]");
diagConfig.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromSeconds(logInterval);
I can not find any offcial documentaion says the logs will be lost when instances is restarted, as far as i know, the logs is stored in Local Storage and it will be upload to Blob storage if you configure the Diagnostics, i think Local Storage won't be cleared
when instances is restarted and your logs can be uploaded after a period of time because upload isn't an immediate operation. Unless your instances was crashed, the logs may lost, but i think the OnStop method also can not be executed when instance was
crashed, so "On Demand Transfer " does not works for this situation.
> i think Local Storage won't be cleared when instances is restarted
There is the flag "Clean on role recycle" for a local storage. I set this flag. Maybe I should try to disable cleaning. Thanks for this suggestion!
> i think the OnStop method also can not be executed when instance was crashed, so "On Demand Transfer " does not works for this situation.
As far as I know there are situations when Azure infrastructure wants to renew the machine for an instance (it closes the old machine and start a new machine for this instance). In this situation the local storage will be lost anyway,
even if I disable cleaning for it. But the OnStop method should be called.
Yes, If Azure Platform update the instace (Stop old instances and re-create a new instance), the OnStop method will be invoked, but when more serious problem cause instances crashed, OnStop method may not be invoked.
I think read queue by application is not a recommended way, if your application get the queues, Diagnostices can not get them twice because every queue could be read for once.
I do assume the OnStop Method returns before the OnDemandTransfer happens, since the demand transfer is initiated asyncronously to run in the background.
What you may need is to wait in your OnStop method until the RoleInstanceDiagnosticManager does not have any active Transfer ( via .GetActiveTransfers() ) anymore. From a quick look in documentation seems there is no WaitHandle or so available so you'll
have to write some code around.
I think the following now. The "BeginOnDemandTransfer" function call really changes only the configuration file in blob storage (in wad-control-container). Once a minute Diagnostic Monitor updates its configuration. This is enough time because 5 minutes
are given for OnStop. But when does Monitor begin the log transfer? My guess is Monitor waits when the scheduled transfer ends (i.e. it can wait several minutes), and only after that it begins OnDemand transfer.
GetActiveTransfers() is used for OnDemand transfers only. Before the "BeginOnDemandTransfer" call GetActiveTransfers() == 0, and after that it's > 0.
When OnStop begins, the system sends the shutdown notification to DiagnosticsAgent.exe. Probably after that Diagnostics Monitor stops to update its configuration once a minute. This can be the cause of OnDemand transfer failing.