Ich habe die folgende Klasse:Variable existieren nicht direkt im aktuellen Kontext nach dem Erstellen es
/// <summary>
/// Represents an implementation of the <see cref="IAspNetCoreLoggingConfigurationBuilder"/> to configure the ASP.NET Core Logging.
/// </summary>
public class AspNetCoreLoggingConfigurationBuilder : IAspNetCoreLoggingConfigurationBuilder
{
#region Properties
/// <summary>
/// Gets the <see cref="ILogSource"/> that's used to write log entries.
/// </summary>
public ILogSource LogSource{ get; private set; }
#endregion
#region IAspNetCoreLoggingConfigurationBuilder Members
/// <summary>
/// Sets the log source that should be used to save log entries.
/// </summary>
/// <param name="logSource">The source </param>
public void SetLogSource(ILogSource logSource)
{
LogSource = logSource;
}
#endregion
}
Ich habe auch ein Verfahren, in dem ich eine Instanz dieser Klasse zu erstellen:
/// <summary>
/// Adds logging to the <see cref="IApplicationBuilder"/> request execution pipeline.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> to configure the application's request pipeline.</param>
/// <param name="configuration">Builder used to configure the ASP.NET Core Logging.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IApplicationBuilder UseAspNetCoreLogging(this IApplicationBuilder app, Action<IAspNetCoreLoggingConfigurationBuilder> configuration)
{
var aspNetLoggerConfiguration = new AspNetCoreLoggingConfigurationBuilder();
configuration(aspNetLoggerConfiguration);
// Add the registered ILogSource into the registered services.
_services.AddInstance(typeof (ILogSource), aspNetLoggerConfiguration.LogSource);
// The entire configuration for the middleware has been done, so return the middleware.
return app.UseMiddleware<AspNetCoreLoggingMiddleware>();
}
Hinweis In der ersten Zeile erstelle ich eine Instanz der Klasse. Wenn ich jedoch diese Variable in einer Uhr überprüfe, bekomme ich, wenn sich mein Cursor in der Zeile configuration(aspNetLoggerConfiguration);
befindet, dass die Variable im aktuellen Kontext nicht existiert.
Erstellen einer Instanz der Variablen funktioniert, wenn Sie es direkt im Überwachungsfenster tun.
Jeder hat eine Ahnung?
P.S. Es ist ein DNX-Projekt, das ich in xUnit testen werde. Der Code wird im Debug-Modus ausgeführt.
Erhalten Sie einen Fehler zur Laufzeit? –
Beim Debuggen oder beim Ausführen der Anwendung ja. Es wird jedoch richtig gebaut. – Complexity
haben Sie versucht, die Methode öffentlich zu machen? – jdweng