public TraceWrapperBase(List<IResultHandler> handlers = null)
        {
            #region Handlers
            Handlers = new List<IResultHandler>();
            if (handlers != null)
            {
                foreach (IResultHandler handler in handlers)
                {
                    if (Handlers.Count<IResultHandler>((h) => h.GetType() == handler.GetType()) == 0)
                    {
                        Handlers.Add(handler);
                    }
                }
            }
            else
            {
                string prefix = "IResultHandler";
                foreach (string handlername in ConfigurationManager.AppSettings.AllKeys
                         .Where(key => key.StartsWith(prefix))
                         .ToArray())
                {

                    IResultHandler handler = ReflectionUtil.CreateInstance<IResultHandler>(ConfigurationManager.AppSettings[handlername]); //CreateHandler(handlerSetting);
                    if (handler != null) handler.Name = handlername.Substring(prefix.Length, handlername.Length - prefix.Length);
                    if (handler != null && Handlers.Count<IResultHandler>((h) => h.Name == handler.Name) == 0)
                    {
                        Handlers.Add(handler);
                    }
                }

                if (Handlers.Count == 0) Handlers.Add(new DefaultEventHandler());
            }
            #endregion
            #region TraceDefinitionFile
            TraceDefinitionFile = new TraceDefinitionFile();
            foreach (IResultHandler handler in Handlers)
            {
                TraceDefinitionFile.Merge(handler.TraceDefinition);
            }
            #endregion
            #region IResultSaveAdapter
            string resultSaveAdapterSetting = ConfigurationManager.AppSettings["IResultSaveAdapter"];
            if (!string.IsNullOrEmpty(resultSaveAdapterSetting))
            {
                resultSaveAdapter = ReflectionUtil.CreateInstance<IResultSaveAdapter>(resultSaveAdapterSetting);
                if (resultSaveAdapter == null) resultSaveAdapter = new FileResultSaveAdapter();
            }
            #endregion
        }
 /// <summary>
 /// </summary>
 /// <param name="trcFile"></param>
 /// <returns></returns>
 public string AsServerSideStoredProcedureStart(TraceDefinitionFile tracefile,string trcFile)
 {
     StringBuilder sb = new StringBuilder();
     sb.Append("            declare @TraceId int \n");
     sb.Append("            declare @maxfilesize  bigint \n");
     sb.Append("            set @maxfilesize = 20 \n");
     sb.Append("            -- create the trace \n");
     sb.Append("            exec sp_trace_create @TraceId output, 2, N'" + trcFile + "',@maxfilesize \n");
     sb.Append("            -- set event and columns to trace \n");
     foreach (KeyValuePair<TraceEventEnum, List<TraceColumn>> kvpair in tracefile)
     {
         foreach (TraceColumn tc in kvpair.Value)
         {
             sb.Append("            exec sp_trace_setevent @TraceId, " + ((int)kvpair.Key).ToString() + "," + ((int)tc).ToString() + ",1 \n");
         }
     }
     sb.Append("            -- start the trace \n");
     sb.Append("            exec sp_trace_setstatus @TraceId, 1 \n");
     sb.Append("            -- check status for our trace \n");
     sb.Append("            select value from fn_trace_getinfo(@TraceId) where property =5 \n");
     sb.Append("            go \n");
     return sb.ToString();
 }