Ejemplo n.º 1
0
        /// <summary>
        /// 初始化日志系统
        /// 在系统运行开始初始化,不存在创建目录文件
        /// </summary>
        /// <param name="configFilename">
        ///     <remarks>
        ///         <para>log4net配置文件路径,支持以下格式:</para>
        ///         <list type="bullet">
        ///             <item>~/config/log4net.config</item>
        ///             <item>~/web.config</item>
        ///             <item>c:\abc\log4net.config</item>
        ///         </list>
        ///     </remarks>
        /// </param>
        public Log4NetLogger(string configFilename = "")
        {
            XmlConfigurator.Configure();
            if (string.IsNullOrEmpty(configFilename))
            {
                string filePath = FileUtility.GetDiskFilePath("~/App_Data/");

                var files = Directory.GetFiles(filePath, "log4net.config");

                //foreach (var file in files)
                //  Console.WriteLine(file);
            }

            string   file           = FileUtility.GetDiskFilePath(configFilename);
            FileInfo configFileInfo = new FileInfo(file);

            if (!configFileInfo.Exists)
            {
                throw new ApplicationException(string.Format("log4net配置文件 {0} 未找到", configFileInfo.FullName));
            }

            if (RunningEnvironment.IsFullTrust())
            {
                XmlConfigurator.ConfigureAndWatch(configFileInfo);
            }
            else
            {
                XmlConfigurator.Configure(configFileInfo);
            }
        }
        internal static RunningEnvironmentConfig For(RunningEnvironment environment)
        {
            switch (environment)
            {
            case RunningEnvironment.AzureTest:
                return(new AzureConfig());

            case RunningEnvironment.Local:
                return(new LocalConfig());

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 3
0
        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = FrameworkDescription != null?FrameworkDescription.GetHashCode() : 0;

                hashCode = (hashCode * 397) ^ (RunningEnvironment != null ? RunningEnvironment.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (EntryAssemblyName != null ? EntryAssemblyName.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (EntryAssemblyVersion != null ? EntryAssemblyVersion.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (LocalTimeString != null ? LocalTimeString.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (MachineName != null ? MachineName.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (OperatingSystemPlatform != null ? OperatingSystemPlatform.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (OperatingSystemArchitecture != null ? OperatingSystemArchitecture.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (OperatingSystemVersion != null ? OperatingSystemVersion.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ProcessArchitecture != null ? ProcessArchitecture.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (ProcessorCount != null ? ProcessorCount.GetHashCode() : 0);
                return(hashCode);
            }
        }
 public override string ToString()
 {
     return($"Service: {Service.ToString()}, RunningEnvironment: {RunningEnvironment.ToString()}, in Azure: {RunningInAzure}");
 }