내 로그를 파일에 쓰려고하는데, 내 응용 프로그램이 중단 될 때마다 로그가 로그 파일에 저장됩니다. StreamWriter를 내게하지 않습니다 그러나, 나는 모든 경로있는 posibility을 시도했지만, 매번 나는 그것이 나에게이 예외가 발생합니다이를 테스트하려고 : 콘솔 출력과 같이SteamWriter가 파일을 만들고 싶지 않습니다.
System.NotSupportedException: The given path's format is not supported.
이 경로는 그러나 괜찮을 것을 :
StartLogging=True Trying to write to C:\Users\Tom\documents\visual studio 2012\Projects\xxx\yyy\bin\Debug\logs\06-11-13_11:51:37.log
이 작동하지 않는 이유를 내가 볼 수 없기 때문에 어떤 도움도 대단히 감사하겠습니다 ...
SaveLog 기능 :
public void SaveLog(bool startLogging = false)
{
DateTime startTime = LogManager.StartTime;
string appPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
string logPath = appPath.Replace("file:\\", "") + "\\logs\\";
string logFile = startTime.ToString("MM-dd-yy_HH:mm:ss") + ".log";
string fullPath = Path.Combine(logPath, logFile);
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}
Console.WriteLine("StartLogging={0} Trying to write to {1}", startLogging, fullPath);
using (StreamWriter writer = new StreamWriter(fullPath, !startLogging))
{
writer.Write("[{0}][{1}] ", Time.ToString("HH:mm:ss:fff"), Level.ToString());
writer.Write(Message);
writer.WriteLine(" ({0} - {1})", Method, Location);
}
}
,536,
경로는 콜론 (:) 문자를 포함 할 수 없습니다. – SWeko
경로 수 있습니다. 디렉토리 및 파일 이름은 사용할 수 없습니다. – spender