Exemple #1
0
        ///// <summary>
        ///// Log Trace ifnormation in the command line
        ///// </summary>
        ///// <param name="e"></param>
        //protected override void LogTrace(Microsoft.Web.Deployment.DeploymentTraceEventArgs args)
        //{
        //    string strMsg = args.Message;
        //    string strEventType =  "Trace";
        //    Framework.MessageImportance messageImportance = Microsoft.Build.Framework.MessageImportance.Low;

        //    if (args is Deployment.DeploymentFileSerializationEventArgs ||
        //        args is Deployment.DeploymentPackageSerializationEventArgs ||
        //        args is Deployment.DeploymentObjectChangedEventArgs ||
        //        args is Deployment.DeploymentSyncParameterEventArgs )
        //    {
        //        //promote those message only for those event
        //        strEventType = "Action";
        //        messageImportance = Microsoft.Build.Framework.MessageImportance.High;
        //    }

        //    if (!string.IsNullOrEmpty(strMsg))
        //    {
        //         switch (args.EventLevel)
        //         {
        //             case System.Diagnostics.TraceLevel.Off:
        //                 break;
        //             case System.Diagnostics.TraceLevel.Error:
        //                 _host.Log.LogError(strMsg);
        //                 break;
        //             case System.Diagnostics.TraceLevel.Warning:
        //                 _host.Log.LogWarning(strMsg);
        //                 break;
        //             default: // Is Warning is a Normal message
        //                 _host.Log.LogMessageFromText(strMsg, messageImportance);
        //                 break;

        //         }
        //    }
        //    // additionally we fire the Custom event for the detail information
        //    CustomBuildWithPropertiesEventArgs customBuildWithPropertiesEventArg = new CustomBuildWithPropertiesEventArgs(args.Message, null, TaskName);

        //    customBuildWithPropertiesEventArg.Add("TaskName", TaskName);
        //    customBuildWithPropertiesEventArg.Add("EventType", strEventType);
        //    AddAllPropertiesToCustomBuildWithPropertyEventArgs(customBuildWithPropertiesEventArg, args);
        //    _host.BuildEngine.LogCustomEvent(customBuildWithPropertiesEventArg);
        //}


        protected override void LogTrace(dynamic args, System.Collections.Generic.IDictionary <string, Microsoft.Build.Framework.MessageImportance> customTypeLoging)
        {
            string strMsg       = args.Message;
            string strEventType = "Trace";

            Framework.MessageImportance messageImportance = Microsoft.Build.Framework.MessageImportance.Low;

            System.Type argsT = args.GetType();
            if (MsDeploy.Utility.IsType(argsT, MSWebDeploymentAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentFileSerializationEventArgs")) ||
                MsDeploy.Utility.IsType(argsT, MSWebDeploymentAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentPackageSerializationEventArgs")) ||
                MsDeploy.Utility.IsType(argsT, MSWebDeploymentAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentObjectChangedEventArgs")) ||
                MsDeploy.Utility.IsType(argsT, MSWebDeploymentAssembly.DynamicAssembly.GetType("Microsoft.Web.Deployment.DeploymentSyncParameterEventArgs")))
            {
                //promote those message only for those event
                strEventType      = "Action";
                messageImportance = Microsoft.Build.Framework.MessageImportance.High;
            }
            else if (customTypeLoging != null && customTypeLoging.ContainsKey(argsT.Name))
            {
                strEventType      = "Trace";
                messageImportance = customTypeLoging[argsT.Name];
            }

            if (!string.IsNullOrEmpty(strMsg))
            {
                System.Diagnostics.TraceLevel level = (System.Diagnostics.TraceLevel)System.Enum.ToObject(typeof(System.Diagnostics.TraceLevel), args.EventLevel);
                switch (level)
                {
                case System.Diagnostics.TraceLevel.Off:
                    break;

                case System.Diagnostics.TraceLevel.Error:
                    _host.Log.LogError(strMsg);
                    break;

                case System.Diagnostics.TraceLevel.Warning:
                    _host.Log.LogWarning(strMsg);
                    break;

                default:     // Is Warning is a Normal message
                    _host.Log.LogMessageFromText(strMsg, messageImportance);
                    break;
                }
            }
            // additionally we fire the Custom event for the detail information
            CustomBuildWithPropertiesEventArgs customBuildWithPropertiesEventArg = new CustomBuildWithPropertiesEventArgs(args.Message, null, TaskName);

            customBuildWithPropertiesEventArg.Add("TaskName", TaskName);
            customBuildWithPropertiesEventArg.Add("EventType", strEventType);
            AddAllPropertiesToCustomBuildWithPropertyEventArgs(customBuildWithPropertiesEventArg, args);
            _host.BuildEngine.LogCustomEvent(customBuildWithPropertiesEventArg);
        }
Exemple #2
0
 // Utility function to log all public instance property to CustomerBuildEventArgs
 private static void AddAllPropertiesToCustomBuildWithPropertyEventArgs(CustomBuildWithPropertiesEventArgs cbpEventArg, System.Object obj)
 {
     if (obj != null)
     {
         System.Type thisType = obj.GetType();
         cbpEventArg.Add("ArgumentType", thisType.ToString());
         System.Reflection.MemberInfo[] arrayMemberInfo = thisType.FindMembers(System.Reflection.MemberTypes.Property, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, null);
         if (arrayMemberInfo != null)
         {
             foreach (System.Reflection.MemberInfo memberinfo in arrayMemberInfo)
             {
                 object val = thisType.InvokeMember(memberinfo.Name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty, null, obj, null, System.Globalization.CultureInfo.InvariantCulture);
                 if (val != null)
                 {
                     cbpEventArg.Add(memberinfo.Name, val);
                 }
             }
         }
     }
 }