internal Task<HttpClient.StackifyWebResponse> SendLogs(LogMsg[] messages)
        {
            try
            {
                StackifyAPILogger.Log("Trying to SendLogs");

                EnsureHttpClient();

                LogMsgGroup group = new LogMsgGroup();

                var identified = _HttpClient.IdentifyApp();

                if (_HttpClient.IsRecentError())
                {
                    var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
                    tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = new ApplicationException("Unable to send logs at this time due to recent error: " + (_HttpClient.LastErrorMessage ?? "")) });
                    return tcs.Task;
                }

                if (!identified)
                {
                    var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
                    tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = new ApplicationException("Unable to send logs at this time. Unable to identify app") });
                    return tcs.Task;
                }

                group.Msgs = messages.ToList();

                //set these fields even if some could be null
                if (_HttpClient.AppIdentity != null)
                {
                    group.CDAppID = _HttpClient.AppIdentity.DeviceAppID;
                    group.CDID = _HttpClient.AppIdentity.DeviceID;
                    group.EnvID = _HttpClient.AppIdentity.EnvID;
                    group.Env = _HttpClient.AppIdentity.Env;
                    group.AppNameID = _HttpClient.AppIdentity.AppNameID;
                    group.AppEnvID = _HttpClient.AppIdentity.AppEnvID;
                    if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.DeviceAlias))
                    {
                        group.ServerName = _HttpClient.AppIdentity.DeviceAlias;
                    }

                    if (!String.IsNullOrWhiteSpace(_HttpClient.AppIdentity.AppName))
                    {
                        group.AppName = _HttpClient.AppIdentity.AppName;
                    }
                }

                var env = EnvironmentDetail.Get(false);

                //We use whatever the identity stuff says, otherwise we use the azure instance name and fall back to the machine name
                if (string.IsNullOrEmpty(group.ServerName))
                {
                    if (!string.IsNullOrEmpty(env.AzureInstanceName))
                    {
                        group.ServerName = env.AzureInstanceName;
                    }
                    else
                    {
                        group.ServerName = Environment.MachineName;
                    }
                }

                //if it wasn't set by the identity call above
                if (string.IsNullOrWhiteSpace(group.AppName))
                {
                    group.AppName = env.AppNameToUse();
                }
                else if (group.AppName.StartsWith("/LM/W3SVC"))
                {
                    group.AppName = env.AppNameToUse();
                }

                group.AppLoc = env.AppLocation;

                if (string.IsNullOrEmpty(group.Env))
                {
                    group.Env = env.ConfiguredEnvironmentName;
                }

                group.Logger = _LoggerName;
                group.Platform = ".net";

                //string jsonData = SimpleJson.SimpleJson.SerializeObject(group);

                string jsonData = JsonConvert.SerializeObject(group, new JsonSerializerSettings() {NullValueHandling = NullValueHandling.Ignore});

                string urlToUse = null;

                urlToUse = System.Web.VirtualPathUtility.AppendTrailingSlash(_HttpClient.BaseAPIUrl) + "Log/Save";

                if (!_ServicePointSet)
                {
                    ServicePointManager.FindServicePoint(urlToUse, null).ConnectionLimit = 10;
                    _ServicePointSet = true;
                }

                StackifyAPILogger.Log("Sending " + messages.Length.ToString() + " log messages");
                var task =
                    _HttpClient.SendAndGetResponseAsync(
                        urlToUse,
                        jsonData, jsonData.Length > 5000);

                return task;

            }
            catch (Exception ex)
            {
                Utils.StackifyAPILogger.Log(ex.ToString());

                var tcs = new TaskCompletionSource<HttpClient.StackifyWebResponse>();
                tcs.SetResult(new HttpClient.StackifyWebResponse() { Exception = ex });
            //                tcs.SetException(ex);
                return tcs.Task;
            }

            return null;
        }