85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace BS.Shared.Core
|
|
{
|
|
public static class DebugUtils
|
|
{
|
|
/// <summary>
|
|
/// Schreibt einen Text in eine Log-Datei auf dem Desktop des angemeldeten Benutzers.
|
|
/// </summary>
|
|
/// <param name="message">Der zu loggende Text.</param>
|
|
public static void WriteToLogFile(string message)
|
|
{
|
|
#if DEBUG
|
|
if(string.IsNullOrWhiteSpace(message))
|
|
{
|
|
return;
|
|
}
|
|
|
|
WriteToLogFile(message, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "BeWoPlanerLog.txt"));
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Schreibt den Text der ToString()-Methode einer Ausnahme in eine Log-Datei auf dem Desktop des angemeldeten Benutzers.
|
|
/// </summary>
|
|
/// <param name="exception">Die zu loggende Ausnahme.</param>
|
|
public static void WriteToLogFile(Exception exception)
|
|
{
|
|
#if DEBUG
|
|
if(exception is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
WriteToLogFile(exception.ToString(), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "BeWoPlanerLog.txt"));
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Schreibt einen Text in die angegebene Log-Datei.
|
|
/// </summary>
|
|
/// <param name="message">Der zu loggende Text.</param>
|
|
/// <param name="pathToLogFile">Der Pfad zur Log-Datei in die der zu loggende Text geschrieben wird.</param>
|
|
public static void WriteToLogFile(string message, string pathToLogFile)
|
|
{
|
|
#if DEBUG
|
|
if(string.IsNullOrWhiteSpace(message))
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
using(var streamWriter = new StreamWriter(pathToLogFile, true))
|
|
{
|
|
streamWriter.WriteLine(message);
|
|
}
|
|
}
|
|
catch(Exception exception)
|
|
{
|
|
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Schreibt den Text der ToString()-Methode einer Ausnahme in die angegebene Log-Datei
|
|
/// </summary>
|
|
/// <param name="exception">Die zu loggende Ausnahme.</param>
|
|
/// <param name="pathToLogFile">Der Pfad zur Log-Datei in die die zu loggende Ausnahme geschrieben wird.</param>
|
|
public static void WriteToLogFile(Exception exception, string pathToLogFile)
|
|
{
|
|
#if DEBUG
|
|
if(exception is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
WriteToLogFile(exception.ToString(), pathToLogFile);
|
|
#endif
|
|
}
|
|
}
|
|
}
|