5

I need source code line number to the log entry through NLog.

Please let me know alternate ways to do it.

<<Log entry>> Line 23 
 <<Log entry>> Line 391

P.S. - 23, 391 are the source code line numbers. Thanks

CuriousBenjamin
  • 709
  • 1
  • 9
  • 26

2 Answers2

11

You may use ${callsite:fileName=true} layout renderer - indicates whether to render the source file name and line number. Documentation.

prashantsunkari
  • 959
  • 7
  • 21
kolbasov
  • 1,548
  • 11
  • 15
  • thanks a lot ppl. it did not work out exactly because I was calling a Log() in a helper class. using callsite gave me file informatin from the callsite class. So i finally used StackFrame and got the line number and the file being used for the same. – CuriousBenjamin Mar 22 '12 at 04:36
  • @CuriousBenjamin When wrapping NLog with custom helper-classes, then one just need to tell NLog. See also: https://stackoverflow.com/questions/7412156/how-to-retain-callsite-information-when-wrapping-nlog – Rolf Kristensen Nov 29 '20 at 10:33
-2

Not sure but you should try this. Hope it will help :D

http://iosdevelopertips.com/cocoa/filename-and-line-number-with-nslog-part-ii.html

and I also found this

NSLog(@"current line: %d",__LINE__);

from this How can I log the current line via NSLog in Cocoa / Objective C?

EDIT sry I dont know that u want C# should try look at this

Do __LINE__ __FILE__ equivalents exist in C#?

Cœur
  • 37,241
  • 25
  • 195
  • 267
crazyoxygen
  • 706
  • 1
  • 11
  • 30