public void CallSiteShouldWorkEvenInlined() { Type loggerType = typeof(Logger); var stacktrace = StackTraceUsageUtils.GetWriteStackTrace(loggerType); var index = LoggerImpl.FindCallingMethodOnStackTrace(stacktrace, loggerType); var logEvent = new LogEventInfo(LogLevel.Error, "logger1", "message1"); logEvent.SetStackTrace(stacktrace, index); Layout l = "${callsite}"; var callSite = l.Render(logEvent); Assert.Equal("NLog.UnitTests.LayoutRenderers.CallSiteTests.CallSiteShouldWorkEvenInlined", callSite); }
public void CallSiteShouldWorkEvenInlined() { var logEvent = new LogEventInfo(LogLevel.Error, "logger1", "message1"); Type loggerType = typeof(Logger); var stacktrace = StackTraceUsageUtils.GetWriteStackTrace(loggerType); var stackFrames = stacktrace.GetFrames(); var index = LoggerImpl.FindCallingMethodOnStackTrace(stackFrames, loggerType) ?? 0; int? indexLegacy = LoggerImpl.SkipToUserStackFrameLegacy(stackFrames, index); logEvent.GetCallSiteInformationInternal().SetStackTrace(stacktrace, index, indexLegacy); Layout l = "${callsite}"; var callSite = l.Render(logEvent); Assert.Equal("NLog.UnitTests.LayoutRenderers.CallSiteTests.CallSiteShouldWorkEvenInlined", callSite); }
public async Task <string> GetAsyncCallSite() { Type loggerType = typeof(Logger); var stacktrace = StackTraceUsageUtils.GetWriteStackTrace(loggerType); var index = LoggerImpl.FindCallingMethodOnStackTrace(stacktrace, loggerType); var logEvent = new LogEventInfo(LogLevel.Error, "logger1", "message1"); logEvent.SetStackTrace(stacktrace, index); await Task.Delay(0); Layout l = "${callsite}"; var callSite = l.Render(logEvent); return(callSite); }
public async Task <string> GetAsyncCallSite() { var logEvent = new LogEventInfo(LogLevel.Error, "logger1", "message1"); #if !NETSTANDARD1_5 Type loggerType = typeof(Logger); var stacktrace = StackTraceUsageUtils.GetWriteStackTrace(loggerType); var stackFrames = stacktrace.GetFrames(); var index = LoggerImpl.FindCallingMethodOnStackTrace(stackFrames, loggerType) ?? 0; int? indexLegacy = LoggerImpl.SkipToUserStackFrameLegacy(stackFrames, index); logEvent.GetCallSiteInformationInternal().SetStackTrace(stacktrace, index, indexLegacy); #endif await Task.Delay(0); Layout l = "${callsite}"; var callSite = l.Render(logEvent); return(callSite); }