/*private void SetServerUrl(HttpContext context = null) * { * if (!_IsInitialised) * { * lock (_initLocker) * { * //Not redunant - this check is more efficient for a 1-time set. * //If it's set, we exit without locking. We want to avoid locking as much as possible, so only do it once (at startup) * if (!_IsInitialised) * { * //First, try to read from the config * var config = ObjectFactory.GetInstance<IConfigRepository>(); * var serverProtocol = config.Get("ServerProtocol", String.Empty); * var domainName = config.Get("ServerDomainName", String.Empty); * var domainPort = config.Get<int?>("ServerPort", null); * * if (!String.IsNullOrWhiteSpace(domainName) && !String.IsNullOrWhiteSpace(serverProtocol) && domainPort.HasValue) * { * Fr8.Infrastructure.Utilities.Server.ServerUrl = String.Format("{0}{1}{2}/", serverProtocol, domainName, * domainPort.Value == 80 ? String.Empty : (":" + domainPort.Value)); * * Fr8.Infrastructure.Utilities.Server.ServerHostName = domainName; * } * else * { * if (context == null) * return; * * //If the config is not set, then we setup our server URL based on the first request * string port = context.Request.ServerVariables["SERVER_PORT"]; * if (port == null || port == "80" || port == "443") * port = ""; * else * port = ":" + port; * * string protocol = context.Request.ServerVariables["SERVER_PORT_SECURE"]; * if (protocol == null || protocol == "0") * protocol = "http://"; * else * protocol = "https://"; * * // *** Figure out the base Url which points at the application's root * Fr8.Infrastructure.Utilities.Server.ServerHostName = context.Request.ServerVariables["SERVER_NAME"]; * string url = protocol + context.Request.ServerVariables["SERVER_NAME"] + port + context.Request.ApplicationPath; * Fr8.Infrastructure.Utilities.Server.ServerUrl = url; * } * _IsInitialised = true; * } * } * } * }*/ public void Application_End() { //Logger.GetLogger().Info("fr8 web shutting down..."); Logger.GetLogger().Warn("fr8 web shutting down..."); // This will give LE background thread some time to finish sending messages to Logentries. var numWaits = 3; while (!AsyncLogger.AreAllQueuesEmpty(TimeSpan.FromSeconds(5)) && numWaits > 0) { numWaits--; } }
/// <summary> /// Dispose should automatically be called by Serilog when it Flushes. /// </summary> /// <remarks>REF: https://github.com/serilog/serilog/wiki/Developing-a-sink#releasing-resources </remarks> public void Dispose() { if (_asyncLogger is null) { return; } var numWaits = 3; while (!AsyncLogger.AreAllQueuesEmpty(TimeSpan.FromSeconds(2)) && numWaits > 0) { numWaits--; } if (numWaits <= 0) { // Hmm... the queue still had/has some items in it and they probably won't be send downthe wire // to Insight Ops ... :/ Console.WriteLine(" *** Failed to flush the Inisight Ops queue 100%"); } }