2

We have an internal error reporting system (inside our functions dll) and one of the info pieces we send is the name of the application that caused it.

Current code:

string applicationname= Assembly.GetCallingAssembly().GetName().Name;

The problem is when the error is send from one of our websites as it sends application names like "App_Code.6p_c415d".

One possible way was determining if the app is an executable or a website dinamically (how do we do that?) and in the case of being a website get the folder containing it or so...

But if you have better ways we are open to any idea ^^

VSP
  • 2,367
  • 8
  • 38
  • 59
  • 1
    try this (this may well give you a meaningful name, but will not detect if your app is Console, Windows, ASP.NET ect)...System.Web.Hosting.HostingEnvironment.ApplicationHost.GetSiteName(); – Matthew Layton Nov 07 '12 at 12:50

2 Answers2

1

You can use a key in the AppSettings to identify your application.

lstern
  • 1,599
  • 14
  • 27
  • Could be but the dll will be used by other people too, the less they have to do (i know this is silly :/) the better...and if they leave it blank we would have to guess which application is... – VSP Nov 08 '12 at 08:30
0

We ended up creating the following function and it works fine:

public static string getApplicationName()
{
    return string.IsNullOrEmpty(HttpRuntime.AppDomainAppId)?
        Assembly.GetEntryAssembly().GetName().Name : 
        new DirectoryInfo(HttpContext.Current.Server.MapPath("")).Name;
}
VSP
  • 2,367
  • 8
  • 38
  • 59