본문 바로가기

C#

[C#] 1개 이상의 로그 파일 가져오는 방법

728x90
반응형
OpenFileDialog openFileDialog = new()
{
	Multiselect = true,
	Filter = "로그 파일 (*.log)|*.log|모든 파일 (*.*)|*.*"
};
openFileDialog.FileOk += (sender, e) =>
{
	OpenFileDialog? dialog = sender as OpenFileDialog;
	if (dialog != null)
	{
		logFileNames = dialog.FileNames.OrderBy(f => f).ToArray();
        	//logFileNames는 string[]으로, Log파일들의 이름을 가져옵니다.
	}
};

if (openFileDialog.ShowDialog() == true)
{
	try
	{
		foreach (string filePath in logFileNames)
		{
			LogFIlePathList.Add(filePath);
            		//LogFilePathList는 ObservableCollection<string>?으로,
            		//해당 로그파일에 담긴 정보들을 리스트 형태로 가져옵니다.
		}

		for (int i = 0; i < LogFIlePathList.Count; i++)
		{
			using StreamReader reader = new(LogFIlePathList[i]);
            		//각각 로그파일 정보를 가져옵니다.
		}
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.ToString());
	}
}
728x90
반응형

'C#' 카테고리의 다른 글

[C# WPF] Google Meet창 띄우기  (4) 2024.03.05