0

I have written a code block to generate log file so that I can get all the functions being called.

I used the Microsoft.Practises.EnterpriseLibrary.Logging dll to get the log file generated can I know how to get that generated.

string procName = "reports_plan_and_proj.plan_v_paid_inv_pay_method_sum";
Logger.Write("SQL:GetPlanvsPaidInvestPmtMthdSummary():: " + procName, "SQL");
Draken
  • 3,134
  • 13
  • 34
  • 54
chaitanya Phani
  • 1
  • 1
  • 1
  • 1
  • 4
    You've told us what you've already done, but not asked a queston..... – Jamiec Apr 21 '17 at 10:22
  • *can i know how to get that generated*, I don't get what your asking here? – Liam Apr 21 '17 at 10:22
  • http://stackoverflow.com/questions/10130504/how-to-get-the-name-of-current-function – Slai Apr 21 '17 at 10:31
  • i have written the above code to get the log generated but it doesn't work and the log file is not getting generated can you please guide me in creating a log file. – chaitanya Phani Apr 21 '17 at 10:34

1 Answers1

1

Let's use a class somehow like this one

public class LogControl
{
    private static string _Path = string.Empty;
    private static bool DEBUG = true;

    public static void Write(string msg)
    {
        _Path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
        try
        {
            using (StreamWriter w = File.AppendText(Path.Combine(_Path, "log.txt")))
            {
                Log(msg, w);
            }
            if (DEBUG)
                Console.WriteLine(msg);
        }
        catch(Exception e)
        {
            //Handle
        }
    }

    static private void Log(string msg, TextWriter w)
    {
        try
        {
            w.Write(Environment.NewLine);
            w.Write("[{0} {1}]", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
            w.Write("\t");
            w.WriteLine(" {0}", msg);
            w.WriteLine("-----------------------");
        }
        catch(Exception e)
        {
                        //Handle
        }
    }
}

You call it using LogControl.Write("I want to log this") And it produce an output like this : [1:19:34 PM Friday, April 21, 2017] I want to log this -------------

Sven Borden
  • 1,070
  • 1
  • 13
  • 29