c# - What is UserStackFrame in NLOG and how to get it? -
in application got logeventinfo.userstackframe property null. want set it, , how set it?
we need make sure first userstackframe. see here.
using system; using system.collections; using system.diagnostics; using system.reflection; using nlog.filters; using nlog.targets; using nlog.internal; namespace nlog { internal sealed class loggerimpl { private loggerimpl() { } private const int stack_trace_skip_methods = 0; private static assembly nlogassembly = typeof(logger).assembly; internal static void write(type loggertype, targetwithfilterchain targets, logeventinfo logevent, logfactory factory) { if (targets == null) return; #if !netcf bool needtrace = false; bool needtracesources = false; int nst = targets.needsstacktrace; if (nst > 0) needtrace = true; if (nst > 1) needtracesources = true; stacktrace stacktrace = null; if (needtrace && !logevent.hasstacktrace) { int firstuserframe = 0; stacktrace = new stacktrace(stack_trace_skip_methods, needtracesources); (int = 0; < stacktrace.framecount; ++i) { system.reflection.methodbase mb = stacktrace.getframe(i).getmethod(); if (mb.declaringtype.assembly == nlogassembly || mb.declaringtype == loggertype) { firstuserframe = + 1; } else { if (firstuserframe != 0) break; } } logevent.setstacktrace(stacktrace, firstuserframe); } #endif (targetwithfilterchain awf = targets; awf != null; awf = awf.next) { target app = awf.target; filterresult result = filterresult.neutral; try { filtercollection filterchain = awf.filterchain; (int = 0; < filterchain.count; ++i) { filter f = filterchain[i]; result = f.check(logevent); if (result != filterresult.neutral) break; } if ((result == filterresult.ignore) || (result == filterresult.ignorefinal)) { if (internallogger.isdebugenabled) { internallogger.debug("{0}.{1} rejecting message because of filter.", logevent.loggername, logevent.level); } if (result == filterresult.ignorefinal) return; continue; } } catch (exception ex) { internallogger.error("filterchain exception: {0}", ex); if (factory.throwexceptions) throw; else continue; } try { app.write(logevent); } catch (exception ex) { internallogger.error("target exception: {0}", ex); if (factory.throwexceptions) throw; else continue; } if (result == filterresult.logfinal) return; } } } }
if want highest level function call, use msdn.
stacktrace st = new stacktrace(); // display recent function call. stackframe sf = st.getframe(0); console.writeline(); console.writeline(" exception in method: "); console.writeline(" {0}", sf.getmethod()); if (st.framecount >1) { // display highest-level function call // in trace. sf = st.getframe(st.framecount-1); console.writeline(" original function call @ top of call stack):"); console.writeline(" {0}", sf.getmethod()); }
Comments
Post a Comment