|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Addition to callsite layout rendererHi!
First of all NLog is something special. It combines fast start, easy to use, flexibility and power. I hope I'll stick with it. I'd like to suggest a new parameter SkipFrames to ${callsite} layout renderer to indicate the number of user frames to be skipped. Suppose I've made Log method to indicate some errors in program. private void Log() { string AdditionalInfo; // ... // Here we fill AdditionalInfo // ... logger.Error("Error: " + AdditionalInfo); } Then I log errors in different parts of my code: private void button1_Click(object sender, EventArgs e) { //... if(someThingWrong) Log(); } But I always get the same method name, file name and file line number. The changes will touch only one file CallSite.cs **** Add private int _skipUserFrames=0; /// <summary> /// The number of user frames to be skipped /// </summary> [System.ComponentModel.DefaultValue(0)] public int SkipFrames { get { return _skipUserFrames; } set { _skipUserFrames = value; } } **** Change this protected internal override void Append(StringBuilder builder, LogEventInfo logEvent) { StackFrame frame = logEvent.UserStackFrame; if (frame != null) { **** to this protected internal override void Append(StringBuilder builder, LogEventInfo logEvent) { if (logEvent.HasStackTrace) { StackFrame frame = logEvent.StackTrace.GetFrame(logEvent.UserStackFrameNumber+SkipFrames); If I got to wrong place, please, advise where i have to go. Gennadiy |
|
|
Re: Addition to callsite layout rendererHello Gennadiy!
> I'd like to suggest a new parameter SkipFrames to ${callsite} layout > renderer to indicate the number of user frames to be skipped. > > Thanks. There is another way to get similar behavior in NLog without modifying existing layout renderers (note that you'd have to modify each LR that uses stack trace information, and you don't know the exact number of frames you'd want to skip). Instead you can pass the declaring Type of the method that users will call and NLog will skip the appropriate number of user frames up to and including this type. You need to build the LogEventInfo structure yourself and pass it to the Log() method of NLog.Logger class. The sample code can be found in the repository: http://svn.nlog-project.org/repos/nlog/trunk/NLog/examples/ExtendingLoggers/ This functionality is available in the latest snapshots (20060824 or later, it's NOT in 1.0 RC1) and will be included in 1.0 RC2 due shortly. Sorry, I don't have time to write more at the moment, but I'll try to post detailed info to the list soon. The snapshots can be found here: http://www.nlog-project.org/snapshots/ Regards, Jarek ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Nlog-list mailing list Nlog-list@... https://lists.sourceforge.net/lists/listinfo/nlog-list |
|
|
Re: Addition to callsite layout rendererThank you. I've got idea. As I understand the basics for it already was in RC1. |
| Free Forum Powered by Nabble | Forum Help |