在我使用OWIN的WebAPI项目中,调用似乎总是返回NULL:
var appAssembly = Assembly.GetEntryAssembly();我也试过:
var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;返回的只有"System.Web“。
如何捕获应用程序的名称、版本?
我正试图在Web项目的Startup项目中捕捉这些信息:
/// <summary>
/// The OWIN startup class.
/// </summary>
public class Startup
{
/// <summary>
/// The necessary OWIN configuration method.
/// </summary>
/// <param name="app">The app being started under OWIN hosting.</param>
public void Configuration(IAppBuilder app)
{
var appAssembly = Assembly.GetEntryAssembly();
Aspect.Logging.LoggingHandler.Initialize(appAssembly, "Hard Coded App Name!");
Log.Information("Starting App...");
// Order is important here. The security wiring must happen first.
ConfigureAuthentication(app);
// Create web configuration and register with WebAPI.
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
// Configure documentation.
ConfigureDocumentation(config);
// Configure support for static files (e.g. index.html).
app.UseFileServer(new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = new PhysicalFileSystem(".")
});
// Start the API.
app.UseWebApi(config);
Log.Information("App started.");
}发布于 2016-01-04 21:19:18
使用:
var appAssembly = typeof(Startup).Assembly;https://stackoverflow.com/questions/34599930
复制相似问题