예제 #1
0
		/// <summary>
		/// Hook the shutdown event
		/// </summary>
		/// <remarks>
		/// <para>
		/// On the full .NET runtime, the static constructor hooks up the 
		/// <c>AppDomain.ProcessExit</c> and <c>AppDomain.DomainUnload</c>> events. 
		/// These are used to shutdown the GodLesZ.Library.Logging system as the application exits.
		/// </para>
		/// </remarks>
		static LoggerManager() {
			try {
				// Register the AppDomain events, note we have to do this with a
				// method call rather than directly here because the AppDomain
				// makes a LinkDemand which throws the exception during the JIT phase.
				RegisterAppDomainEvents();
			} catch (System.Security.SecurityException) {
				LogLog.Debug(declaringType, "Security Exception (ControlAppDomain LinkDemand) while trying " +
					"to register Shutdown handler with the AppDomain. LoggerManager.Shutdown() " +
					"will not be called automatically when the AppDomain exits. It must be called " +
					"programmatically.");
			}

			// Dump out our assembly version into the log if debug is enabled
			LogLog.Debug(declaringType, GetVersionInfo());

			// Set the default repository selector
#if NETCF
			s_repositorySelector = new CompactRepositorySelector(typeof(GodLesZ.Library.Logging.Repository.Hierarchy.Hierarchy));
#else

			// Look for the RepositorySelector type specified in the AppSettings 'GodLesZ.Library.Logging.RepositorySelector'
			string appRepositorySelectorTypeName = SystemInfo.GetAppSetting("GodLesZ.Library.Logging.RepositorySelector");
			if (appRepositorySelectorTypeName != null && appRepositorySelectorTypeName.Length > 0) {
				// Resolve the config string into a Type
				Type appRepositorySelectorType = null;
				try {
					appRepositorySelectorType = SystemInfo.GetTypeFromString(appRepositorySelectorTypeName, false, true);
				} catch (Exception ex) {
					LogLog.Error(declaringType, "Exception while resolving RepositorySelector Type [" + appRepositorySelectorTypeName + "]", ex);
				}

				if (appRepositorySelectorType != null) {
					// Create an instance of the RepositorySelectorType
					object appRepositorySelectorObj = null;
					try {
						appRepositorySelectorObj = Activator.CreateInstance(appRepositorySelectorType);
					} catch (Exception ex) {
						LogLog.Error(declaringType, "Exception while creating RepositorySelector [" + appRepositorySelectorType.FullName + "]", ex);
					}

					if (appRepositorySelectorObj != null && appRepositorySelectorObj is IRepositorySelector) {
						s_repositorySelector = (IRepositorySelector)appRepositorySelectorObj;
					} else {
						LogLog.Error(declaringType, "RepositorySelector Type [" + appRepositorySelectorType.FullName + "] is not an IRepositorySelector");
					}
				}
			}

			// Create the DefaultRepositorySelector if not configured above 
			if (s_repositorySelector == null) {
				s_repositorySelector = new DefaultRepositorySelector(typeof(GodLesZ.Library.Logging.Repository.Hierarchy.Hierarchy));
			}
#endif
		}
예제 #2
0
        /// <summary>
        /// Hook the shutdown event
        /// </summary>
        /// <remarks>
        /// <para>
        /// On the full .NET runtime, the static constructor hooks up the
        /// <c>AppDomain.ProcessExit</c> and <c>AppDomain.DomainUnload</c>> events.
        /// These are used to shutdown the GodLesZ.Library.Logging system as the application exits.
        /// </para>
        /// </remarks>
        static LoggerManager()
        {
            try {
                // Register the AppDomain events, note we have to do this with a
                // method call rather than directly here because the AppDomain
                // makes a LinkDemand which throws the exception during the JIT phase.
                RegisterAppDomainEvents();
            } catch (System.Security.SecurityException) {
                LogLog.Debug(declaringType, "Security Exception (ControlAppDomain LinkDemand) while trying " +
                             "to register Shutdown handler with the AppDomain. LoggerManager.Shutdown() " +
                             "will not be called automatically when the AppDomain exits. It must be called " +
                             "programmatically.");
            }

            // Dump out our assembly version into the log if debug is enabled
            LogLog.Debug(declaringType, GetVersionInfo());

            // Set the default repository selector
#if NETCF
            s_repositorySelector = new CompactRepositorySelector(typeof(GodLesZ.Library.Logging.Repository.Hierarchy.Hierarchy));
#else
            // Look for the RepositorySelector type specified in the AppSettings 'GodLesZ.Library.Logging.RepositorySelector'
            string appRepositorySelectorTypeName = SystemInfo.GetAppSetting("GodLesZ.Library.Logging.RepositorySelector");
            if (appRepositorySelectorTypeName != null && appRepositorySelectorTypeName.Length > 0)
            {
                // Resolve the config string into a Type
                Type appRepositorySelectorType = null;
                try {
                    appRepositorySelectorType = SystemInfo.GetTypeFromString(appRepositorySelectorTypeName, false, true);
                } catch (Exception ex) {
                    LogLog.Error(declaringType, "Exception while resolving RepositorySelector Type [" + appRepositorySelectorTypeName + "]", ex);
                }

                if (appRepositorySelectorType != null)
                {
                    // Create an instance of the RepositorySelectorType
                    object appRepositorySelectorObj = null;
                    try {
                        appRepositorySelectorObj = Activator.CreateInstance(appRepositorySelectorType);
                    } catch (Exception ex) {
                        LogLog.Error(declaringType, "Exception while creating RepositorySelector [" + appRepositorySelectorType.FullName + "]", ex);
                    }

                    if (appRepositorySelectorObj != null && appRepositorySelectorObj is IRepositorySelector)
                    {
                        s_repositorySelector = (IRepositorySelector)appRepositorySelectorObj;
                    }
                    else
                    {
                        LogLog.Error(declaringType, "RepositorySelector Type [" + appRepositorySelectorType.FullName + "] is not an IRepositorySelector");
                    }
                }
            }

            // Create the DefaultRepositorySelector if not configured above
            if (s_repositorySelector == null)
            {
                s_repositorySelector = new DefaultRepositorySelector(typeof(GodLesZ.Library.Logging.Repository.Hierarchy.Hierarchy));
            }
#endif
        }