Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Debug output to console and a log

public static class Logger
{
    public static StringBuilder LogString = new StringBuilder();
    public static void WriteLine(string str)
    {
        Console.WriteLine(str);
        LogString.Append(str).Append(Environment.NewLine);
    }
    public static void Write(string str)
    {
        Console.Write(str);
        LogString.Append(str);

    }
    public static void SaveLog(bool Append = false, string Path = "./Log.txt")
    {
        if (LogString != null && LogString.Length > 0)
        {
            if (Append)
            {
                using (StreamWriter file = System.IO.File.AppendText(Path))
                {
                    file.Write(LogString.ToString());
                    file.Close();
                    file.Dispose();
                }
            }
            else
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(Path))
                {
                    file.Write(LogString.ToString());
                    file.Close();
                    file.Dispose();
                }
            }               
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: C# data base sql 
Csharp :: mental retardation 
Csharp :: list.SkipWhile in c# 
Csharp :: c# timestamp 
Csharp :: c# rotate sum array 
Csharp :: c# e-mail send 
Csharp :: call a .NET assembly from C or c++ 
Csharp :: c# parsing datetime from string irrespctive of culture 
Csharp :: unity generate random offset position around a gameobject 
Csharp :: Unity FPS camera z axis rotating problem 
Csharp :: button next for picturebox c# 
Csharp :: razor preview 
Csharp :: querstring fromat asp.net c# 
Csharp :: get picked item xamarin 
Csharp :: stackoverflow array c# 
Csharp :: global variable startup file .net core api 
Csharp :: Diplay player final score in new scene in unity 
Csharp :: c# string with double quotes inside 
Csharp :: c# console.writeline next line 
Csharp :: Handling aggregation responses with NEST c# 
Csharp :: c# download image from url 
Csharp :: close windows by esc wpf 
Csharp :: unity AppDomain 
Csharp :: DefaultContractResolver .net exclude null values JsonSerializerSettings ContractResolver DefaultContractResolver 
Csharp :: material.icons for wpf 
Csharp :: unity random.insideunitcircle 
Csharp :: unity matchinfo 
Csharp :: C# Blocks without statements 
Csharp :: binary search tree c# stackoverflow 
Csharp :: REMOVE BOTTOM TAB XAMARIN FORMS 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =