Unofficial CardLife revival project, pronounced like "celery"
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

49 lignes
1.5KB

  1. using System.IO;
  2. using System.Net;
  3. using System.Reflection;
  4. using System.Text;
  5. using HarmonyLib;
  6. namespace CLre_server.WebStatus
  7. {
  8. public class LogEndpoints
  9. {
  10. [WebEndpoint("/l/current")]
  11. private static void FullLog(HttpListenerContext ctx)
  12. {
  13. if (CustomLogger_GetFileNameToUse_Patch.currentLogFile == null)
  14. {
  15. byte[] output = Encoding.UTF8.GetBytes("No log file available");
  16. ctx.Response.OutputStream.Write(output, 0, output.Length);
  17. return;
  18. }
  19. // copy file because log is already open for writing
  20. string copyFilename = CustomLogger_GetFileNameToUse_Patch.currentLogFile + ".copy";
  21. File.Copy(CustomLogger_GetFileNameToUse_Patch.currentLogFile, copyFilename, true);
  22. FileStream logFile = new FileStream(copyFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
  23. logFile.CopyTo(ctx.Response.OutputStream);
  24. logFile.Close();
  25. }
  26. }
  27. [HarmonyPatch]
  28. class CustomLogger_GetFileNameToUse_Patch
  29. {
  30. internal static string currentLogFile = null;
  31. [HarmonyPostfix]
  32. public static void AfterMethodCall(string __result)
  33. {
  34. #if DEBUG
  35. API.Utility.Logging.MetaLog($"Current logfile is {__result}");
  36. #endif
  37. currentLogFile = __result;
  38. }
  39. [HarmonyTargetMethod]
  40. public static MethodBase Target()
  41. {
  42. return AccessTools.Method("CustomLogger:GetFileNameToUse");
  43. }
  44. }
  45. }