static Log() { /*if (ProgramRoutines.IsWebContext) - !!!crashes on Xamarin!!! * throw new Exception("Log is disabled in web context."); * * if (ProgramRoutines.IsWebContext) * ProcessName = System.Web.Compilation.BuildManager.GetGlobalAsaxType().BaseType.Assembly.GetName(false).Name; * else*/ System.Reflection.Assembly a = System.Reflection.Assembly.GetEntryAssembly(); //!!!when using WCF hapenned that GetEntryAssembly() is NULL if (a == null) { a = System.Reflection.Assembly.GetCallingAssembly(); } ProcessName = System.Reflection.Assembly.GetEntryAssembly().GetName(false).Name; AppDir = AppDomain.CurrentDomain.BaseDirectory.TrimEnd(System.IO.Path.DirectorySeparatorChar); AssemblyRoutines.AssemblyInfo ai = new AssemblyRoutines.AssemblyInfo(Assembly.GetEntryAssembly()); CompanyName = string.IsNullOrWhiteSpace(ai.Company) ? "CliverSoft" : ai.Company; //!!!no write permission on macOS!!! CompanyCommonDataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + System.IO.Path.DirectorySeparatorChar + CompanyName; AppCommonDataDir = CompanyCommonDataDir + System.IO.Path.DirectorySeparatorChar + Log.ProcessName; CompanyUserDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + System.IO.Path.DirectorySeparatorChar + CompanyName; AppUserDataDir = CompanyUserDataDir + System.IO.Path.DirectorySeparatorChar + Log.ProcessName; }
static Log() { {//this block works on Windows desktop, XamarinMAC, NT service, Android Assembly headAssembly = Assembly.GetEntryAssembly(); //!!!when using WCF or Android, GetEntryAssembly() == NULL if (headAssembly == null) { headAssembly = Assembly.GetCallingAssembly(); } ProgramName = headAssembly.GetName(false).Name; //AppDir = AppDomain.CurrentDomain.BaseDirectory?.TrimEnd(Path.DirectorySeparatorChar);!!!gives not an app's dir on WCF or Android if (headAssembly.Location != null) { AppDir = PathRoutines.GetFileDir(headAssembly.Location); } else//just in case. It hardly can come here { Uri u = new Uri(headAssembly.CodeBase); AppDir = PathRoutines.GetFileDir(u.LocalPath); } AssemblyRoutines.AssemblyInfo ai = new AssemblyRoutines.AssemblyInfo(headAssembly); CompanyName = ai.Company; } //{ // HashSet<Assembly> assemblies = new HashSet<Assembly>(); // Assembly a = null; // StackTrace stackTrace = new StackTrace(); // foreach (StackFrame st in stackTrace.GetFrames()) // { // Assembly b = st.GetMethod().DeclaringType.Assembly; // if (b == null) // break; // a = b; // assemblies.Add(a); // } // if (a == null) // a = Assembly.GetEntryAssembly(); // AssemblyName = a.FullName; // Process p = Process.GetCurrentProcess(); // AppDir = PathRoutines.GetFileDir(p.MainModule.FileName); // FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(p.MainModule.FileName); // if (fvi != null) // { // CompanyName = fvi.CompanyName; // //ProductName = fvi.ProductName; // } //} //!!!No write permission on macOS //CompanyCommonDataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + Path.DirectorySeparatorChar + CompanyName; //!!!No write permission on macOS //AppCompanyCommonDataDir = CompanyCommonDataDir + Path.DirectorySeparatorChar + ProcessName; //CompanyUserDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + CompanyName; //AppCompanyUserDataDir = CompanyUserDataDir + Path.DirectorySeparatorChar + ProcessName; }