优化日志输出
This commit is contained in:
parent
f1a371575c
commit
1cc886a23e
|
@ -35,6 +35,8 @@ namespace N_m3u8DL_RE.Common.Log
|
||||||
|
|
||||||
public static void InitLogFile()
|
public static void InitLogFile()
|
||||||
{
|
{
|
||||||
|
if (!IsWriteFile) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var logDir = Path.GetDirectoryName(Environment.ProcessPath) + "/Logs";
|
var logDir = Path.GetDirectoryName(Environment.ProcessPath) + "/Logs";
|
||||||
|
@ -195,5 +197,33 @@ namespace N_m3u8DL_RE.Common.Log
|
||||||
}
|
}
|
||||||
ErrorMarkUp(data);
|
ErrorMarkUp(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This thing will only write to the log file.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <param name="ps"></param>
|
||||||
|
public static void Extra(string data, params object[] ps)
|
||||||
|
{
|
||||||
|
if (IsWriteFile && File.Exists(LogFilePath))
|
||||||
|
{
|
||||||
|
data = ReplaceVars(data, ps);
|
||||||
|
var plain = GetCurrTime() + " " + "EXTRA: " + data.RemoveMarkup();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//进入写入
|
||||||
|
LogWriteLock.EnterWriteLock();
|
||||||
|
using (StreamWriter sw = File.AppendText(LogFilePath))
|
||||||
|
{
|
||||||
|
sw.WriteLine(plain, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
//释放占用
|
||||||
|
LogWriteLock.ExitWriteLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ namespace N_m3u8DL_RE.Common.Util
|
||||||
|
|
||||||
if (redirectedUrl != url)
|
if (redirectedUrl != url)
|
||||||
{
|
{
|
||||||
|
Logger.Extra($"Redirected => {redirectedUrl}");
|
||||||
return await DoGetAsync(redirectedUrl, headers);
|
return await DoGetAsync(redirectedUrl, headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(PublishAot)' == 'true' and '$(RuntimeIdentifier)' != 'win-arm64' and '$(RuntimeIdentifier)' != 'linux-arm64'">
|
<ItemGroup Condition="'$(PublishAot)' == 'true' and '$(RuntimeIdentifier)' != 'win-arm64' and '$(RuntimeIdentifier)' != 'linux-arm64'">
|
||||||
<PackageReference Include="PublishAotCompressed" Version="0.0.4" />
|
<PackageReference Include="PublishAotCompressed" Version="1.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -130,6 +130,7 @@ namespace N_m3u8DL_RE.Downloader
|
||||||
{
|
{
|
||||||
Logger.DebugMarkUp($"[grey]{ex.Message.EscapeMarkup()} retryCount: {retryCount}[/]");
|
Logger.DebugMarkUp($"[grey]{ex.Message.EscapeMarkup()} retryCount: {retryCount}[/]");
|
||||||
Logger.Debug(url + " " + ex.ToString());
|
Logger.Debug(url + " " + ex.ToString());
|
||||||
|
Logger.Extra($"Ah oh!{Environment.NewLine}RetryCount => {retryCount}{Environment.NewLine}Exception => {ex.Message}{Environment.NewLine}Url => {url}");
|
||||||
if (retryCount-- > 0)
|
if (retryCount-- > 0)
|
||||||
{
|
{
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
|
@ -137,6 +138,7 @@ namespace N_m3u8DL_RE.Downloader
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Logger.Extra($"The retry attempts have been exhausted and the download of this segment has failed.{Environment.NewLine}Exception => {ex.Message}{Environment.NewLine}Url => {url}");
|
||||||
Logger.WarnMarkUp($"[grey]{ex.Message.EscapeMarkup()}[/]");
|
Logger.WarnMarkUp($"[grey]{ex.Message.EscapeMarkup()}[/]");
|
||||||
}
|
}
|
||||||
//throw new Exception("download failed", ex);
|
//throw new Exception("download failed", ex);
|
||||||
|
|
|
@ -151,6 +151,7 @@ namespace N_m3u8DL_RE
|
||||||
foreach (var item in option.Headers)
|
foreach (var item in option.Headers)
|
||||||
{
|
{
|
||||||
headers[item.Key] = item.Value;
|
headers[item.Key] = item.Value;
|
||||||
|
Logger.Extra($"User-Defined Header => {item.Key}: {item.Value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var parserConfig = new ParserConfig()
|
var parserConfig = new ParserConfig()
|
||||||
|
|
Loading…
Reference in New Issue