Ejemplo n.º 1
0
        }         // Log

        /// <summary>
        ///
        /// The format of the columns will be:  DateTime, Severity, IpAddress, SessionId, ComponentName, MethodName, VmcId, ThreadId, Msg
        /// </summary>
        /// <param name="i_eSeverity"></param>
        /// <param name="i_iVmcId"></param>
        /// <param name="i_sComponent"></param>
        /// <param name="i_sMsg"></param>
        /// <returns></returns>
        public override bool Log(eSeverity i_eSeverity, int i_iVmcId, string i_sComponentName, string i_sMsg)
        {
            bool             bRet = true, bRes = true;
            string           sComponentName = i_sComponentName, sMethodName = "", sVmc = "", sThread = "", sRem = "";
            LoggerThreadInfo oInfo = null;
            StackTrace       oST   = null;

            try
            {
                SetLastError(0, "");
                oInfo = new LoggerThreadInfo();
                oST   = new StackTrace(2);                                              // Skip two frames to avoid the overhead of getting a full stack trace

                // First check to see if we need to log this message or not
                if (i_eSeverity >= m_FilterLevel)
                {
                    bRes = ThreadInfoDictSingleton.GetInstance().TryGetValue(Thread.CurrentThread.Name, out oInfo);                             // Don't need to check return value, we'll just use the empty strings assigned in the constructor.
                    if (!bRes)
                    {
                        // This isn't always an error, some threads (like pooled or event-handlers) won't be named.
                        if (oInfo == null)
                        {
                            oInfo = new LoggerThreadInfo();
                        }
                    }

                    sVmc    = oInfo.m_sVmcId;
                    sThread = oInfo.m_sThreadId;
                    bRes    = ReplaceIndexesIfEmbedded(i_sMsg, ref sVmc, ref sThread, out sRem);

                    if (sComponentName.Length == 0)
                    {
                        sComponentName = oST.GetFrame(0).GetMethod().ReflectedType.FullName;
                    }
                    else
                    {
                        sComponentName = oInfo.m_sComponentName;
                    }
                    sComponentName = StripExtension(sComponentName);

                    sMethodName = oST.GetFrame(0).GetMethod().ReflectedType.FullName + "." + oST.GetFrame(0).GetMethod().Name;
                    oST         = null;

                    m_Logger.Log(ConvertSeverityToNSLevel(i_eSeverity), string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", i_eSeverity.ToString(), oInfo.m_sIpAddress, oInfo.m_sSessionId, sComponentName, sMethodName, sVmc, sThread, sRem));
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                SetLastError(-1, "Caught exception in Log(3): " + exc.ToString());
                Console.Error.WriteLine(m_sLastError);
            }

            return(bRet);
        }         // Log
Ejemplo n.º 2
0
        }         // ReplaceIndexesIfEmbedded

        /// <summary>
        ///
        /// The format of the columns will be:  DateTime, Severity, IpAddress, SessionId, ComponentName, MethodName, VmcId, ThreadId, Msg
        /// </summary>
        /// <param name="i_eSeverity"></param>
        /// <param name="i_sMsg"></param>
        /// <returns></returns>
        public override bool Log(eSeverity i_eSeverity, string i_sMsg)
        {
            bool             bRet = true, bRes = true;
            string           sComponentName = "", sMethodName = "", sVmc = "", sThread = "", sRem = "";
            LoggerThreadInfo oInfo = null;
            StackTrace       oST   = null;

            try
            {
                SetLastError(0, "");
                oInfo = new LoggerThreadInfo();
                oST   = new StackTrace(2);                                              // Skip two frames to avoid the overhead of getting a full stack trace

                // First check to see if we need to log this message or not
                if (i_eSeverity >= m_FilterLevel)
                {
                    bRes = ThreadInfoDictSingleton.GetInstance().TryGetValue(Thread.CurrentThread.Name, out oInfo);
                    if (!bRes)
                    {
                        // This isn't always an error, some threads (like pooled or event-handlers) won't be named.
//Console.WriteLine("!!!!!{0} In Log(2) TryGetValue failed, calling method '{1}'", DateTime.Now.ToString(), oST.ToString());
                        if (oInfo == null)
                        {
                            oInfo = new LoggerThreadInfo();
                        }
                    }

                    sVmc    = oInfo.m_sVmcId;
                    sThread = oInfo.m_sThreadId;
                    bRes    = ReplaceIndexesIfEmbedded(i_sMsg, ref sVmc, ref sThread, out sRem);

                    if (oInfo.m_sComponentName.Length == 0)
                    {
                        sComponentName = oST.GetFrame(0).GetMethod().Module.Name;
                    }
                    else
                    {
                        sComponentName = oInfo.m_sComponentName;
                    }
                    sComponentName = StripExtension(sComponentName);

                    sMethodName = oST.GetFrame(0).GetMethod().DeclaringType.FullName + "." + oST.GetFrame(0).GetMethod().Name;
                    oST         = null;

                    m_Logger.Log(ConvertSeverityToNSLevel(i_eSeverity), string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}", i_eSeverity.ToString(), oInfo.m_sIpAddress, oInfo.m_sSessionId, sComponentName, sMethodName, sVmc, sThread, sRem));
                }
                else
                {
                    // Below the filter level
                    //Console.WriteLine("Log(2).Log() else - i_eSeverity = '{0}', m_FilterLevel = '{1}'.", i_eSeverity.ToString(), m_FilterLevel.ToString());
                }
            }
            catch (Exception exc)
            {
                bRet = false;
                SetLastError(-1, string.Format("Caught exception in Log(2), calling method '{0}': '{1}'", oST.ToString(), exc.ToString()));
                Console.Error.WriteLine(DateTime.Now.ToString() + " " + m_sLastError);
            }

            return(bRet);
        }         // Log