Logs(Log File)

Ask general questions here.
Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Logs(Log File)

Post by Praveen597 » Fri Sep 16, 2011 2:02 pm

Logs are very important for tracking the defects. We can know exactly where the code is failing to do our defined task.
Do we have any predefined methods for maintaining a log for all the actions done through code.
Or else, we manually need to write our own cod for logs.?

Any information on this is very helpful.

Thank you,
Praveen

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Logs(Log File)

Post by sdaly » Fri Sep 16, 2011 2:29 pm

See the Report class....

Here is a wee example, I use the .net StackTrace class so it outputs the class/method name too...

You can also do Report.Success(), Report.Failure(), Report.Warn(), Report.Debug etc...


Report.Setup(ReportLevel.Info, currentTestReportName, true);

LogInfo("information!!!");

Report.End();


public static void LogInfo(string info)
{
StackTrace stackTrace = new StackTrace();
string location = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name + "::" + stackTrace.GetFrame(1).GetMethod().Name ;
Report.Info(location, info);
}

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Logs(Log File)

Post by omayer » Mon Sep 19, 2011 2:48 pm

Great Example .Thanks Scott
Tipu

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Logs(Log File)

Post by Praveen597 » Tue Sep 20, 2011 12:20 pm

Thanks for your reply.


Can I have C # code please ...?

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Logs(Log File)

Post by sdaly » Tue Sep 20, 2011 12:23 pm

That is C# :?

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Logs(Log File)

Post by Praveen597 » Thu Sep 22, 2011 2:00 pm

"StackTrace stackTrace = new StackTrace();
string location = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name + "::" + "

This one is not working with ranorex...!

Please help me out.
I am new for C#.

Praveen597
Posts: 27
Joined: Sat Aug 27, 2011 9:41 am

Re: Logs(Log File)

Post by Praveen597 » Thu Sep 22, 2011 2:52 pm

Hi Sdaly ,
It is working fine with;

System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace();

Thank alot buddy. It completely my mistake to over look the code . Sorry for that.
And keep helping me..........!! :P

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: Logs(Log File)

Post by sdaly » Thu Sep 22, 2011 5:27 pm

You could also bring that namespace into scope by adding -

Code: Select all

using System.Diagnostics
:mrgreen:

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: Logs(Log File)

Post by omayer » Thu Sep 29, 2011 2:02 am

Where do I use this code on .cs file, like I am calling method enterEmailAddress(); should i use the below code before calling the method or any advise please.

Report.Setup(ReportLevel.Info, currentTestReportName, true);

LogInfo("information!!!");

Report.End();


public static void LogInfo(string info)
{
StackTrace stackTrace = new StackTrace();
string location = stackTrace.GetFrame(1).GetMethod().DeclaringType.Name + "::" + stackTrace.GetFrame(1).GetMethod().Name ;
Report.Info(location, info);
}
Tipu