Remotely/Agent.Installer.Win/Utilities/Logger.cs
Jared Goodwin 3f8d63c2c0
Azure Pipelines, Docker, and embedded server data. (#543)
* Add Azure Pipelines yml.

* Remove Server Installer.

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Update signtool.exe

* Update Release Build.yml

* Update Publish.ps1

* Update pipeline and Dockerfile.

* Move docker files.

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Update Dockerfile

* Move files.

* Update Dockerfile

* Update Dockerfile

* Create RewritableStream.

* Finish implementation of rewritable stream and embedded data searcher.

* Remove RelayCode.

* Get branding from default org if orgId is missing.

* Update README.md

* Remove AppConstants.ServerUrl.  Fix main module file path.

* Update submodule.

* Extract embedded data in Program.cs.

* Add logging.  Update submodule.

* Remove size block.  BinaryWriter prefixes size.

* Remove unused async

* Update Immense.RemoteControl

* Update Release Build.yml for Azure Pipelines

* Update Release Build.yml for Azure Pipelines

* Use UpgradeService for determining out of date clients.
2022-12-31 19:10:40 -08:00

82 lines
2.4 KiB
C#

using System;
using System.IO;
using System.Linq;
namespace Remotely.Agent.Installer.Win.Utilities
{
public class Logger
{
private static readonly string _logPath = Path.Combine(Path.GetTempPath(), "Remotely", "Installer.log");
private static readonly object _writeLock = new object();
public static void Debug(string message)
{
lock (_writeLock)
{
#if DEBUG
CheckLogFileExists();
File.AppendAllText(_logPath, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss.fff}\t[Debug]\t{message}{Environment.NewLine}");
#endif
System.Diagnostics.Debug.WriteLine(message);
}
}
public static void Write(string message)
{
try
{
lock (_writeLock)
{
CheckLogFileExists();
File.AppendAllText(_logPath, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss.fff}\t[Info]\t{message}{Environment.NewLine}");
Console.WriteLine(message);
}
}
catch { }
}
public static void Write(Exception ex)
{
lock (_writeLock)
{
try
{
CheckLogFileExists();
var exception = ex;
while (exception != null)
{
File.AppendAllText(_logPath, $"{DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss.fff}\t[Error]\t{exception?.Message}\t{exception?.StackTrace}\t{exception?.Source}{Environment.NewLine}");
Console.WriteLine(exception.Message);
exception = exception.InnerException;
}
}
catch { }
}
}
private static void CheckLogFileExists()
{
if (!File.Exists(_logPath))
{
File.Create(_logPath).Close();
}
if (File.Exists(_logPath))
{
var fi = new FileInfo(_logPath);
while (fi.Length > 1000000)
{
var content = File.ReadAllLines(_logPath);
File.WriteAllLines(_logPath, content.Skip(10));
fi = new FileInfo(_logPath);
}
}
}
}
}