/// <summary> /// Gets an "application name" for the executing application by looking at /// the hosted app name (.NET Framework on IIS only), assembly name, and process name. /// </summary> /// <returns>The default service name.</returns> private static string GetApplicationName() { try { try { if (TryLoadAspNetSiteName(out var siteName)) { return(siteName); } } catch (Exception ex) { // Unable to call into System.Web.dll Log.SafeLogError(ex, "Unable to get application name through ASP.NET settings"); } return(Assembly.GetEntryAssembly()?.GetName().Name ?? ProcessHelpers.GetCurrentProcessName()); } catch (Exception ex) { Log.SafeLogError(ex, "Error creating default service name."); return(null); } }
static LibLogScopeEventSubscriber() { #if NETFRAMEWORK // Check if IIS automatic instrumentation has set the AppDomain property to indicate the PreStartInit state // If the property is not set, we must rely on a different method of determining the state object state = AppDomain.CurrentDomain.GetData(NamedSlotName); if (state is bool boolState) { _performAppDomainFlagChecks = true; _executingIISPreStartInit = boolState; } else { _performAppDomainFlagChecks = false; _executingIISPreStartInit = true; try { string processName = ProcessHelpers.GetCurrentProcessName(); if (!processName.Equals("w3wp", StringComparison.OrdinalIgnoreCase) && !processName.Equals("iisexpress", StringComparison.OrdinalIgnoreCase)) { // IIS is not running so we do not anticipate issues with IIS PreStartInit code execution _executingIISPreStartInit = false; } } catch (Exception ex) { Log.Error(ex, "Error obtaining the process name for quickly validating IIS PreStartInit condition."); } } if (_executingIISPreStartInit) { Log.Warning("Automatic logs injection detected that IIS is still initializating. The {Source} will be checked at the start of each trace to only enable automatic logs injection when IIS is finished initializing.", _performAppDomainFlagChecks ? "AppDomain" : "System.Diagnostics.StackTrace"); } #endif InitResolvers(); }