Ejemplo n.º 1
0
        //private struct ThreadUsage
        //{
        //    public string SrcMethod { get; set; }
        //    public string TransID { get; set; }
        //}


        //ConcurrentDictionary<string, ThreadUsage> _ThreadInfo = new ConcurrentDictionary<string, ThreadUsage>();

        /// <summary>
        /// Should call CanSend() before this. Did not also put that call in here to improve performance. Makes more sense to do it earlier so it can skip other steps up the chain.
        /// </summary>
        /// <param name="msg"></param>
        public void QueueLogMessage(Models.LogMsg msg)
        {
            try
            {
                if (msg == null)
                {
                    return;
                }

                if (!_TimerStarted)
                {
                    EnsureTimer();
                }

                try
                {
                    if (string.IsNullOrEmpty(msg.Th))
                    {
                        msg.Th = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                    }
                }
                catch
                {
                    // ignore
                }

#if NETFULL
                try
                {
                    if (string.IsNullOrEmpty(msg.TransID))
                    {
                        var stackifyRequestID = CallContext.LogicalGetData("Stackify-RequestID");

                        if (stackifyRequestID != null)
                        {
                            msg.TransID = stackifyRequestID.ToString();
                        }
                    }

                    if (string.IsNullOrEmpty(msg.TransID))
                    {
                        //gets from Trace.CorrelationManager.ActivityId but doesnt assume it is guid since it technically doesn't have to be
                        //not calling the CorrelationManager method because it blows up if it isn't a guid
                        var correltionManagerId = CallContext.LogicalGetData("E2ETrace.ActivityID");

                        if (correltionManagerId != null && correltionManagerId is Guid && ((Guid)correltionManagerId) != Guid.Empty)
                        {
                            msg.TransID = correltionManagerId.ToString();
                        }
                    }

                    if (string.IsNullOrEmpty(msg.TransID))
                    {
                        if (_IsWebApp &&
                            System.Web.Hosting.HostingEnvironment.IsHosted &&
                            System.Web.HttpContext.Current != null &&
                            System.Web.HttpContext.Current.Handler != null)
                        {
                            msg.TransID = System.Web.HttpContext.Current.Request.GetHashCode().ToString();
                        }
                    }
                }
                catch (System.Web.HttpException ex)
                {
                    StackifyAPILogger.Log("Request not available \r\n" + ex.ToString());
                }
                catch (Exception ex)
                {
                    StackifyAPILogger.Log("Error figuring out TransID \r\n" + ex.ToString());
                }

                if (_IsWebApp &&
                    System.Web.Hosting.HostingEnvironment.IsHosted &&
                    System.Web.HttpContext.Current != null &&
                    System.Web.HttpContext.Current.Handler != null)
                {
                    var context = System.Web.HttpContext.Current;

                    msg.UrlFull = context.Request.Url.ToString();

                    if (context.Items.Contains("Stackify.ReportingUrl"))
                    {
                        msg.UrlRoute = context.Items["Stackify.ReportingUrl"].ToString();
                    }
                    else
                    {
                        var resolver = new RouteResolver(new HttpContextWrapper(context));

                        var route = resolver.GetRoute();

                        if (!string.IsNullOrEmpty(route.Action))
                        {
                            msg.UrlRoute = route.ToString();
                        }
                    }

                    if (string.IsNullOrEmpty(msg.UrlRoute))
                    {
                        if (string.IsNullOrWhiteSpace(context.Request.AppRelativeCurrentExecutionFilePath) == false)
                        {
                            HelperFunctions.CleanPartialUrl(context.Request.AppRelativeCurrentExecutionFilePath.TrimStart('~'));
                        }
                    }
                }
#endif

                _MessageBuffer.Enqueue(msg);
            }
            catch (Exception ex)
            {
                StackifyAPILogger.Log("#LogQueue #QueueLogMessage failed", ex);
            }
        }
Ejemplo n.º 2
0
        //private struct ThreadUsage
        //{
        //    public string SrcMethod { get; set; }
        //    public string TransID { get; set; }
        //}


        //ConcurrentDictionary<string, ThreadUsage> _ThreadInfo = new ConcurrentDictionary<string, ThreadUsage>();

        /// <summary>
        /// Should call CanSend() before this. Did not also put that call in here to improve performance. Makes more sense to do it earlier so it can skip other steps up the chain.
        /// </summary>
        /// <param name="msg"></param>
        public void QueueLogMessage(Models.LogMsg msg)
        {
            try
            {
                if (msg == null)
                {
                    return;
                }

                if (!_TimerStarted)
                {
                    EnsureTimer();
                }


                //try
                //{

                //    if (string.IsNullOrEmpty(msg.Th))
                //    {
                //        msg.Th = System.Threading.Thread.CurrentThread.ManagedThreadId.ToString();
                //    }
                //}
                //catch
                //{
                //}

                //try
                //{
                //    if (string.IsNullOrEmpty(msg.TransID))
                //    {

                //        Object stackifyRequestID = CallContext.LogicalGetData("Stackify-RequestID");

                //        if (stackifyRequestID != null)
                //        {
                //            msg.TransID = stackifyRequestID.ToString();
                //        }
                //    }

                //    if (string.IsNullOrEmpty(msg.TransID))
                //    {
                //        //gets from Trace.CorrelationManager.ActivityId but doesnt assume it is guid since it technically doesn't have to be
                //        //not calling the CorrelationManager method because it blows up if it isn't a guid
                //        Object correltionManagerId = CallContext.LogicalGetData("E2ETrace.ActivityID");

                //        if (correltionManagerId != null && correltionManagerId is Guid && ((Guid)correltionManagerId) != Guid.Empty)
                //        {
                //            msg.TransID = correltionManagerId.ToString();
                //        }
                //    }

                //    if (string.IsNullOrEmpty(msg.TransID))
                //    {
                //        if (_IsWebApp && System.Web.Hosting.HostingEnvironment.IsHosted
                //                 && System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Handler != null &&
                //                 System.Web.HttpContext.Current.Request != null)
                //        {
                //            msg.TransID = System.Web.HttpContext.Current.Request.GetHashCode().ToString();
                //        }

                //    }
                //}
                //catch (System.Web.HttpException ex)
                //{
                //    StackifyAPILogger.Log("Request not available \r\n" + ex.ToString());
                //}
                //catch(Exception ex)
                //{
                //    StackifyAPILogger.Log("Error figuring out TransID \r\n" + ex.ToString());
                //}



                //if (_IsWebApp && System.Web.Hosting.HostingEnvironment.IsHosted
                //    && System.Web.HttpContext.Current != null
                //    && System.Web.HttpContext.Current.Handler != null
                //    && System.Web.HttpContext.Current.Request != null)
                //{
                //    var context = System.Web.HttpContext.Current;

                //    msg.UrlFull = context.Request.Url.ToString();

                //    if (context.Items != null && context.Items.Contains("Stackify.ReportingUrl"))
                //    {
                //        msg.UrlRoute = context.Items["Stackify.ReportingUrl"].ToString();
                //    }
                //    else
                //    {
                //        RouteResolver resolver = new RouteResolver(context);

                //        var route = resolver.GetRoute();

                //        if (!string.IsNullOrEmpty(route.Action))
                //        {
                //            msg.UrlRoute = route.ToString();
                //        }
                //    }


                //    if (string.IsNullOrEmpty(msg.UrlRoute))
                //    {
                //        HelperFunctions.CleanPartialUrl(
                //            context.Request.AppRelativeCurrentExecutionFilePath.TrimStart('~'));
                //    }


                //}



                _MessageBuffer.Enqueue(msg);
            }
            catch
            {
            }
        }