how to write log using c#

Ranorex Spy, Recorder, and Studio.
prasanna
Posts: 10
Joined: Fri Jan 23, 2015 11:23 am

how to write log using c#

Post by prasanna » Tue Feb 03, 2015 11:52 am

hi,
how to write log in a particular location using c#

CookieMonster
Certified Professional
Certified Professional
Posts: 74
Joined: Mon Aug 14, 2006 7:17 pm
Location: CH

Re: how to write log using c#

Post by CookieMonster » Tue Feb 03, 2015 12:53 pm

Hi Prasanna,

Could you please give more details about which log you want to use.
The Ranorex result log, or the NLog framework?

Regards
Dan
Last edited by CookieMonster on Tue Feb 03, 2015 4:36 pm, edited 1 time in total.

prasanna
Posts: 10
Joined: Fri Jan 23, 2015 11:23 am

Re: how to write log using c#

Post by prasanna » Tue Feb 03, 2015 1:35 pm

Could you please explain about NLog framework

CookieMonster
Certified Professional
Certified Professional
Posts: 74
Joined: Mon Aug 14, 2006 7:17 pm
Location: CH

Re: how to write log using c#

Post by CookieMonster » Tue Feb 03, 2015 4:35 pm

Hi Prasanna,
  • 1. Create a Ranorex Solution

    2. In the recording on the user code file you create a method.

    3. Add the Ranorex.Libs. Or Download NLog.
    If you use the class LoggerFactory, then you will get the Ranorex internal use only message, and you will be advised that have to add Ranorex.Libs. to your project.

    4. If you add the reference over the LoggerFactory, you can delete this code line.

    5. Add this lines to into the code :)
    https://github.com/nlog/NLog/wiki/Configuration-API

    6. Now on your output directory a file.txt will be created. After build and running.
If you want to store your log file somewhere else, may you can do it somehow with these code lines. But I haven't tried it.

Code: Select all

FileTarget target = LogManager.Configuration.FindTargetByName(targetName) as FileTarget;
target.FileName = filename;
But by the way, why are you not using the Ranorex Report instated of using NLog?

Cheers
Dan

prasanna
Posts: 10
Joined: Fri Jan 23, 2015 11:23 am

Re: how to write log using c#

Post by prasanna » Wed Feb 04, 2015 6:07 am

I used Report.Log it is just showing the message in report so i asked about NLog framework.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: how to write log using c#

Post by krstcs » Wed Feb 04, 2015 3:10 pm

I think the question was more about WHY you aren't using the Ranorex Report logging mechanism.

So, why do you feel the Ranorex Report is not acceptable, in your case, for logging information?

Is there something that you are having trouble with in the Ranorex Report?


I've found that it is very versatile and easy to work with for all the logging I do.
Shortcuts usually aren't...