■ 커스텀 액션을 사용하는 방법을 보여준다.
[TestAction 프로젝트]
▶ ILogHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
using System; namespace TestAction { /// <summary> /// 로그 헬퍼 인터페이스 /// </summary> public interface ILogHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Method #region 메시지 쓰기 - WriteMessage(message) /// <summary> /// 메시지 쓰기 /// </summary> /// <param name="message">메시지</param> void WriteMessage(string message); #endregion #region 로그 쓰기 - WriteLog(format, parameterArray) /// <summary> /// 로그 쓰기 /// </summary> /// <param name="format">포맷 문자열</param> /// <param name="parameterArray">매개 변수 배열</param> void WriteLog(string format, params object[] parameterArray); #endregion #region 에러 로그 쓰기 - WriteErrorLog(exception, caption) /// <summary> /// 에러 로그 쓰기 /// </summary> /// <param name="exception">예외</param> /// <param name="caption">제목 문자열</param> void WriteErrorLog(Exception exception, string caption); #endregion #region 에러 로그 쓰기 - WriteErrorLog(exception, caption) /// <summary> /// 에러 로그 쓰기 /// </summary> /// <param name="message">예외 메시지</param> /// <param name="caption">제목 문자열</param> void WriteErrorLog(string message, string caption); #endregion #region 덤프 로그 쓰기 - WriteDumpLog(sourceObject, caption) /// <summary> /// 덤프 로그 쓰기 /// </summary> /// <param name="sourceObject">예외</param> /// <param name="caption">제목 문자열</param> void WriteDumpLog(object sourceObject, string caption); #endregion } } |
▶ FileLogHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
using System; using System.IO; namespace TestAction { /// <summary> /// 파일 로그 헬퍼 /// </summary> public class FileLogHelper : ILogHelper { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 동기 객체 /// </summary> private object syncObject; /// <summary> /// 로그 루트 디렉토리 경로 /// </summary> private string logRootDirectoryPath; /// <summary> /// 파일명 /// </summary> private string fileName; /// <summary> /// 파일 경로 /// </summary> private string filePath; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - FileLogHelper(logRootDirectoryPath, fileName) /// <summary> /// 생성자 /// </summary> /// <param name="logRootDirectoryPath">로그 루트 디렉토리 경로</param> /// <param name="fileName">파일명</param> public FileLogHelper(string logRootDirectoryPath, string fileName) { this.syncObject = new object(); this.logRootDirectoryPath = logRootDirectoryPath; this.fileName = fileName; this.filePath = Path.Combine(this.logRootDirectoryPath, this.fileName); if(!Directory.Exists(this.logRootDirectoryPath)) { Directory.CreateDirectory(this.logRootDirectoryPath); } } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 메시지 쓰기 - WriteMessage(message) /// <summary> /// 메시지 쓰기 /// </summary> /// <param name="message">메시지</param> public void WriteMessage(string message) { lock(this.syncObject) { using(StreamWriter writer = File.AppendText(this.filePath)) { writer.WriteLine(message); } } } #endregion #region 로그 쓰기 - WriteLog(format, parameterArray) /// <summary> /// 로그 쓰기 /// </summary> /// <param name="format">포맷 문자열</param> /// <param name="parameterArray">매개 변수 배열</param> public void WriteLog(string format, params object[] parameterArray) { string message; if(parameterArray.Length == 0) { message = format; } else { message = string.Format(format, parameterArray); } string log = string.Format("[{0}] {1}", DateTime.Now.ToString("HH:mm:ss"), message); WriteMessage(log); } #endregion #region 에러 로그 쓰기 - WriteErrorLog(exception, source) /// <summary> /// 에러 로그 쓰기 /// </summary> /// <param name="exception">예외</param> /// <param name="source">소스 문자열</param> public void WriteErrorLog(Exception exception, string source) { lock(this.syncObject) { string title = string.Format("[{0}] {1}", DateTime.Now.ToString("HH:mm:ss"), source); using(StreamWriter writer = File.AppendText(this.filePath)) { writer.WriteLine(title); writer.WriteLine("--------------------------------------------------"); writer.WriteLine(exception.ToString()); writer.WriteLine("--------------------------------------------------"); } } } #endregion #region 에러 로그 쓰기 - WriteErrorLog(message, source) /// <summary> /// 에러 로그 쓰기 /// </summary> /// <param name="message">예외 메시지</param> /// <param name="source">소스 문자열</param> public void WriteErrorLog(string message, string source) { lock (this.syncObject) { string title = string.Format("[{0}] {1}", DateTime.Now.ToString("HH:mm:ss"), source); using (StreamWriter writer = File.AppendText(this.filePath)) { writer.WriteLine(title); writer.WriteLine("--------------------------------------------------"); writer.WriteLine(message); writer.WriteLine("--------------------------------------------------"); } } } #endregion #region 덤프 로그 쓰기 - WriteDumpLog(sourceObject, caption) /// <summary> /// 덤프 로그 쓰기 /// </summary> /// <param name="sourceObject">예외</param> /// <param name="caption">제목 문자열</param> public void WriteDumpLog(object sourceObject, string caption) { lock(this.syncObject) { string title = string.Format("[{0}] {1}", DateTime.Now.ToString("HH:mm:ss"), caption); using(StreamWriter writer = File.AppendText(this.filePath)) { writer.WriteLine(title); writer.WriteLine("--------------------------------------------------"); writer.WriteLine(sourceObject.ToString()); writer.WriteLine("--------------------------------------------------"); } } } #endregion } } |
▶ CustomAction.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
using Microsoft.Deployment.WindowsInstaller; namespace TestAction { /// <summary> /// 커스텀 액션 /// </summary> public class CustomAction { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 버전 /// </summary> private static string _version = "V1.0.0"; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 최초 설치 시작 액션 실행하기 - ExecuteFirstInstallStartAction(session) /// <summary> /// 최초 설치 시작 액션 실행하기 /// </summary> /// <param name="session">세션</param> /// <returns>액션 결과</returns> [CustomAction] public static ActionResult ExecuteFirstInstallStartAction(Session session) { ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log"); logHelper.WriteLog($"ExecuteFirstInstallStartAction : {_version}"); return ActionResult.Success; } #endregion #region 최초 설치 종료 액션 실행하기 - ExecuteFirstInstallEndAction(session) /// <summary> /// 최초 설치 종료 액션 실행하기 /// </summary> /// <param name="session">세션</param> /// <returns>액션 결과</returns> [CustomAction] public static ActionResult ExecuteFirstInstallEndAction(Session session) { ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log"); logHelper.WriteLog($"ExecuteFirstInstallEndAction : {_version}"); return ActionResult.Success; } #endregion #region 업그레이드 설치 시작 액션 실행하기 - ExecuteUpgradeInstallStartAction(session) /// <summary> /// 업그레이드 설치 시작 액션 실행하기 /// </summary> /// <param name="session">세션</param> /// <returns>액션 결과</returns> [CustomAction] public static ActionResult ExecuteUpgradeInstallStartAction(Session session) { ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log"); logHelper.WriteLog($"ExecuteUpgradeInstallStartAction : {_version}"); return ActionResult.Success; } #endregion #region 업그레이드 설치 종료 액션 실행하기 - ExecuteUpgradeInstallEndAction(session) /// <summary> /// 업그레이드 설치 종료 액션 실행하기 /// </summary> /// <param name="session">세션</param> /// <returns>액션 결과</returns> [CustomAction] public static ActionResult ExecuteUpgradeInstallEndAction(Session session) { ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log"); logHelper.WriteLog($"ExecuteUpgradeInstallEndAction : {_version}"); return ActionResult.Success; } #endregion #region 설치 제거 시작 액션 실행하기 - ExecuteUninstallStartAction(session) /// <summary> /// 설치 제거 시작 액션 실행하기 /// </summary> /// <param name="session">세션</param> /// <returns>액션 결과</returns> [CustomAction] public static ActionResult ExecuteUninstallStartAction(Session session) { ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log"); logHelper.WriteLog($"ExecuteUninstallStartAction : {_version}"); return ActionResult.Success; } #endregion #region 설치 제거 종료 액션 실행하기 - ExecuteUninstallEndAction(session) /// <summary> /// 설치 제거 종료 액션 실행하기 /// </summary> /// <param name="session">세션</param> /// <returns>액션 결과</returns> [CustomAction] public static ActionResult ExecuteUninstallEndAction(Session session) { ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log"); logHelper.WriteLog($"ExecuteUninstallEndAction : {_version}"); return ActionResult.Success; } #endregion } } |
※ Wix Toolset와 Wix Toolset 비주얼 스튜디오 확장이 설치되어 있어야 한다.