Skip to content

How to use in Console App

rsdevvm edited this page Feb 6, 2019 · 1 revision

App.config


<appSettings> <add key="EnableLog" value="true" /> <add key="LogFolder" value="" /> <add key="LogFilePrefix" value="UtilityPOC" /> </appSettings>

In Program.cs


static void Main(string[] args)

    {

        string executionMode = "Release";

#if DEBUG executionMode = "Debug"; #endif

        try
        {
            Console.ForegroundColor = ConsoleColor.White;
            Utility.LogEntry("--------------------------------------  Application Started [" + executionMode + "] ------------------------------------------------------");
            DateTime start = DateTime.Now;

            // Add your Code here for Testing 


            Console.ForegroundColor = ConsoleColor.White;
            Utility.LogEntry("Total Completion Duration in (ms):  " + (DateTime.Now - start).TotalMilliseconds);
            Utility.LogEntry2(string.Format("Successfully Completed."));

        }
        catch (Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Utility.LogEntry(string.Format("Exception : {0} , Stack Trace: {1}", ex.Message, Utility.GetFullException(ex)));
            Utility.LogEntry(string.Format("Failed."));
            Console.ForegroundColor = ConsoleColor.White;
        }
        // If working in debug mode , need to see the output at console so let it wait there.
        if (System.Diagnostics.Debugger.IsAttached)
        {
            Console.Write("\nPress any key to exit... ");
            Console.ReadKey(true);
        }
     
    }
Clone this wiki locally