Log4net (또는 다른 로깅 프레임 워크) 대 네이티브 .net 파일로 작성하는 것의 이점은 무엇입니까? 지금까지 파일에 쓸 유틸리티 클래스를 사용했습니다. 이러한 프레임 워크 내 수업 (나를 위해 잘 작동) 내 수업을 도랑과 일부 로깅 프레임 워크로 변환 할 수있는 지점이 그래서 기본적으로 내 질문에 종료 몰랐.net 네이티브 파일 대 어떤 로깅 프레임 워크 대
class FileUtils
{
string mPath;
private static object locker = new Object();
public void createNewLogFile(string path)
{
try
{
lock (locker)
{
mPath = path;
string backUpPath = path + @".bak";
FileInfo MyFile = new FileInfo(path);
Directory.CreateDirectory(Path.GetDirectoryName(path));
if (File.Exists(path))
{
if (new FileInfo(path).Length > Math.Pow(2, 20))
{
if (File.Exists(backUpPath))
{
File.Delete(backUpPath);
}
File.Copy(path, backUpPath);
}
}
}
}
catch (Exception ex)
{
// outputFile.Close();
var t = ex;
throw;
}
}
public void log (string fileLocation ,bool newLine, params string[] input)
{
createNewLogFile(fileLocation);
using (StreamWriter outputFile = File.AppendText(mPath))
{
outputFile.AutoFlush = true;
try
{
if (newLine)
outputFile.Write(Environment.NewLine + DateTime.Now.ToString("dd-MM-yy HH:mm:ss "));
for (int i = 0; i < input.Length; i++)
{
outputFile.Write(input[i] + " ");
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
outputFile.Close();
}
}
}
}
나는 두려워서, 이것은 일종의 의견을 기반으로합니다. 물론 로깅 프레임 워크 **에는 많은 이점이 있습니다. 런타임에서도 구성 가능합니다. 바퀴를 재발 명할 필요가 없습니다. 출력은 파일에 바인딩되지 않습니다 (Windows 이벤트 로그, 전자 메일, 데이터베이스 등에 로그 할 수 있습니다). * 많은 작업을 처리하므로 로깅 방법보다는 기본 작업에 집중할 수 있습니다. – Fildor