1

I have a few different apps under one app type running on a local Service Fabric cluster (1 node). Some are stateless, some are stateful. The logging is done using Serilog. The problem is that all of the logged stack traces never have line numbers.

The deployment is done by publishing the SF project through Visual Studio using "Debug" configuration. I checked the SfDevCluster folder and the PDBs for the executables are there.

Am I missing something?

Edit: log setup

public static LoggerConfiguration CreateBaseLogConfiguration(bool writeToConsole = true)
{
    const string outputTemplate =
        "[{Timestamp:HH:mm:ss} {Level} {RequestId}] {Message}{NewLine}{Exception}";

    var config = new LoggerConfiguration()
        .MinimumLevel.Debug()
        .MinimumLevel.Override("Microsoft", LogEventLevel.Information);

    if (writeToConsole)
        config.WriteTo.Console(outputTemplate: outputTemplate);

    return config;
}

var mainLoggerConfiguration = AddOutOfProcessLogging(CreateBaseLogConfiguration(true)
                                .Enrich.FromLogContext()
                                .Enrich.WithProperty("Service", "MyService")
                                .Enrich.WithProperty("Source", "Api"), shouldUseSeq);

Log.Logger = mainLoggerConfiguration.CreateLogger();

public static LoggerConfiguration AddOutOfProcessLogging(LoggerConfiguration loggerConfiguration, bool useSeq)
{
    if (useSeq)
    {
        var seqServer = "http://localhost:5341";
        return loggerConfiguration
            .WriteTo.Seq(seqServer,
                period: TimeSpan.FromMilliseconds(500),
                compact: true);
    }
    else
    {
        var sumoConfig = new FabricConfigurationProvider("Logging");
        var sumoLogicUrl = sumoConfig.GetValue("SumologicUrl");
        var sourceCategory = sumoConfig.GetValue("SumoSourceCategory");

        return loggerConfiguration
            .WriteTo.SumoLogic(sumoLogicUrl, sourceName: "Serilog", sourceCategory: sourceCategory, textFormatter: new RenderedCompactJsonFormatter());
    }
}

Both Seq and SumoLogic do not have line numbers in the logged stack traces.

Exception from the logs:

"@x": "System.Exception: Correlation failed.
           at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.<HandleRequestAsync>d__12.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at React.AspNet.BabelFileMiddleware.<Invoke>d__5.MoveNext()
        --- End of stack trace from previous location where exception was thrown ---
           at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
           at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
           at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()",
"SourceContext": "Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware",

Exception I added in a controller's method:

System.ArgumentException: For testing purposes.
   at MyProject.Controllers.MyController.<Import>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
Pavel S
  • 68
  • 8
  • Logs are generated properly when you run application from the Visual studio ? You need to share the logging configuration and how are you logging in the code. Can you also share the log entry which does not have line number? – Chetan Jun 07 '18 at 10:46
  • @ChetanRanpariya thank you for your time, I updated my question with the requested details. I do not run the application from VS, for debugging I attach to the processes spawned by SF. The application is working fine, it's just that logged exceptions never have line numbers. Have been using serilog for ages, never had such issues with it before (or any logger for that matter), so I suspect it's something to do with SF. – Pavel S Jun 07 '18 at 11:14
  • Looks like this exception is happening even before the application code is run. Look at https://stackoverflow.com/questions/49280220/identityserver4-correlation-failed-error-with-external-provider. That's why serilog is not having line number details – Chetan Jun 07 '18 at 11:17
  • @ChetanRanpariya That's just the first exception I found in the log, we've had more all over the place while developing the solution. Since the project started a couple months ago, I have never seen a single line number in any log coming from any of the SF apps. – Pavel S Jun 07 '18 at 11:19
  • May be you can try by throwing an exception intentionally from code and see if that logs the line numbers. – Chetan Jun 07 '18 at 11:22
  • @ChetanRanpariya just added a "threw new ArgEx..." in a method and wrapped the call to that method with a try/catch that uses the static global logger "Log.Logger.Fatal" to log it. My question has the stack trace, still no line numbers regrettably :( – Pavel S Jun 07 '18 at 11:34

0 Answers0