mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-22 23:30:13 +01:00
parent
ae1184320f
commit
c601541249
@ -4,7 +4,7 @@ namespace Logging;
|
|||||||
|
|
||||||
public class FileLogger : LoggerBase
|
public class FileLogger : LoggerBase
|
||||||
{
|
{
|
||||||
private string logFilePath { get; }
|
internal string logFilePath { get; }
|
||||||
private const int MaxNumberOfLogFiles = 5;
|
private const int MaxNumberOfLogFiles = 5;
|
||||||
|
|
||||||
public FileLogger(string logFilePath, Encoding? encoding = null) : base (encoding)
|
public FileLogger(string logFilePath, Encoding? encoding = null) : base (encoding)
|
||||||
|
@ -8,6 +8,7 @@ public class Logger : TextWriter
|
|||||||
private static readonly string LogDirectoryPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
private static readonly string LogDirectoryPath = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
||||||
? "/var/log/tranga-api"
|
? "/var/log/tranga-api"
|
||||||
: Path.Join(Directory.GetCurrentDirectory(), "logs");
|
: Path.Join(Directory.GetCurrentDirectory(), "logs");
|
||||||
|
public string? logFilePath => _fileLogger?.logFilePath;
|
||||||
public override Encoding Encoding { get; }
|
public override Encoding Encoding { get; }
|
||||||
public enum LoggerType
|
public enum LoggerType
|
||||||
{
|
{
|
||||||
@ -69,4 +70,9 @@ public class Logger : TextWriter
|
|||||||
{
|
{
|
||||||
return _memoryLogger.GetNewLines();
|
return _memoryLogger.GetNewLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string[] GetLog()
|
||||||
|
{
|
||||||
|
return _memoryLogger.GetLogMessages();
|
||||||
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ public class MemoryLogger : LoggerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] GetLogMessage()
|
public string[] GetLogMessages()
|
||||||
{
|
{
|
||||||
return Tail(Convert.ToUInt32(_logMessages.Count));
|
return Tail(Convert.ToUInt32(_logMessages.Count));
|
||||||
}
|
}
|
||||||
|
@ -394,6 +394,27 @@ public class Server : GlobalBase
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "LogMessages":
|
||||||
|
if (logger is null || !File.Exists(logger?.logFilePath))
|
||||||
|
{
|
||||||
|
SendResponse(HttpStatusCode.NotFound, response);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
SendResponse(HttpStatusCode.OK, response, logger.GetLog());
|
||||||
|
break;
|
||||||
|
case "LogFile":
|
||||||
|
if (logger is null || !File.Exists(logger?.logFilePath))
|
||||||
|
{
|
||||||
|
SendResponse(HttpStatusCode.NotFound, response);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
string logDir = new FileInfo(logger.logFilePath).DirectoryName!;
|
||||||
|
string tmpFilePath = Path.Join(logDir, "Tranga.log");
|
||||||
|
File.Copy(logger.logFilePath, tmpFilePath);
|
||||||
|
SendResponse(HttpStatusCode.OK, response, new FileStream(tmpFilePath, FileMode.Open));
|
||||||
|
File.Delete(tmpFilePath);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
SendResponse(HttpStatusCode.BadRequest, response);
|
SendResponse(HttpStatusCode.BadRequest, response);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user