var appAssembly = Assembly.GetEntryAssembly(); & OWN - 不要混合?
var appAssembly = Assembly.GetEntryAssembly(); & OWN - don't mix?
看来,在我使用 OWIN 的 WebAPI 项目中,调用总是 returns NULL:
var appAssembly = Assembly.GetEntryAssembly();
我也试过:
var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;
returns 就是 "System.Web"。
如何获取应用名称、版本???
我正试图在 Web API 项目启动时捕获此信息:
/// <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.");
}
使用:
var appAssembly = typeof(Startup).Assembly;
看来,在我使用 OWIN 的 WebAPI 项目中,调用总是 returns NULL:
var appAssembly = Assembly.GetEntryAssembly();
我也试过:
var entryAssembly = new StackTrace().GetFrames().Last().GetMethod().Module.Assembly;
returns 就是 "System.Web"。
如何获取应用名称、版本???
我正试图在 Web API 项目启动时捕获此信息:
/// <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.");
}
使用:
var appAssembly = typeof(Startup).Assembly;