示例#1
0
        internal static void WriteActionNameToLog(Session session, string className)
        {
            // Записываем в файл, если он существует.
              string logFileName = Path.Combine(Path.GetTempPath(), "STInstallLogger.log");
              if (!File.Exists(logFileName))
            return;

              System.Text.StringBuilder builder = new System.Text.StringBuilder();

              if (!sessionIsInitialized)
              {
            sessionIsInitialized = true;
            builder.AppendLine("#New Session");

            if (!session.GetMode(InstallRunMode.Scheduled) && !session.GetMode(InstallRunMode.Rollback))
            {
              builder.AppendLine("Current Install Status: " + session.GetService<ISessionCurrentInstallStatusExtension>().GetStatus());

              builder.AppendLine("#Variables");

              string[] variables = new string[] { "Installed", "PATCH", "REMOVE", "REINSTALL",
                                              "UPGRADINGPRODUCTCODE", "ACTION", "ADDLOCAL",
                                              "REINSTALLMODE", "Preselected", "RESUME" };
              foreach (string state in variables)
            builder.AppendLine(string.Format(@"{0}=""{1}""", state, session[state]));
            }

            builder.AppendLine("#InstallRunMode");
            foreach (var e in Enum.GetValues(typeof(InstallRunMode)))
            {
              builder.AppendLine(string.Format(@"{0}=""{1}""", e.ToString(), session.GetMode((InstallRunMode)e)));
            }

            builder.AppendLine();
              }

              builder.AppendLine(string.Format("{0} Action: {1}, Class: {2}", DateTime.Now, GetActionName(), className));

              #region Запись в файл

              using (StreamWriter file = new StreamWriter(logFileName, true))
              {
            file.WriteLine(builder.ToString());
              }

              #endregion
        }