Skip to content

Commit

Permalink
Write logs to process releative path
Browse files Browse the repository at this point in the history
Because Servicy usally runs on SYSTEM account, it can't write to temp folder. So to fix this you need to write somewhere, but not in releative user directory
  • Loading branch information
DareFox committed Feb 12, 2022
1 parent 56b2e88 commit 3c651c7
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions IdleSharedLib/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ namespace IdleSharedLib
public class Logger
{
private static string file = $"{DateTimeOffset.Now.ToUnixTimeSeconds()}-{Environment.ProcessId}-{Process.GetCurrentProcess().ProcessName}.txt";
private static string dir = Environment.CurrentDirectory + "/logs";
public static void Log(string message)
{
var formatedMessage = $"[LOG, {DateTime.Now}] " + message.Trim();
Console.WriteLine(formatedMessage);

var dir = $"{Path.GetTempPath()}/IdleAppStarter/";

Console.WriteLine(formatedMessage);

Directory.CreateDirectory(dir);
File.AppendAllText(dir + file, formatedMessage + "\n");
Expand All @@ -23,8 +22,6 @@ public static void LogToFile(string message)
{
var formatedMessage = $"[LOG, {DateTime.Now}] " + message.Trim();

var dir = $"{Path.GetTempPath()}/IdleAppStarter/";

Directory.CreateDirectory(dir);
File.AppendAllText(dir + file, formatedMessage + "\n");
}
Expand Down

1 comment on commit 3c651c7

@DareFox
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как же он чувствует этот английский. Servicy, usally

Please sign in to comment.