/// <summary> /// Internal method to get pertinent version info. /// </summary> /// <returns>A string of version info.</returns> private static string GetVersionInfo() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); #if NETSTANDARD1_3 Assembly myAssembly = typeof(LoggerManager).GetTypeInfo().Assembly; sb.Append($"log4net assembly [{myAssembly.FullName}]. "); //sb.Append($"Loaded from [{myAssembly.Location}]. "); // TODO Assembly.Location available in netstandard1.5 //GLEB sb.AppendFormat("(.NET Framework [{0}] on {1}", RuntimeInformation.FrameworkDescription, RuntimeInformation.OSDescription); string frameworkDescription; try { frameworkDescription = RuntimeInformation.FrameworkDescription; } catch { frameworkDescription = null; } sb.AppendFormat("(.NET Framework [{0}] on {1}", frameworkDescription ?? "?", RuntimeInformation.OSDescription); #else Assembly myAssembly = Assembly.GetExecutingAssembly(); sb.Append("log4net assembly [").Append(myAssembly.FullName).Append("]. "); sb.Append("Loaded from [").Append(SystemInfo.AssemblyLocationInfo(myAssembly)).Append("]. "); sb.Append("(.NET Runtime [").Append(Environment.Version.ToString()).Append("]"); #if (!SSCLI) sb.Append(" on ").Append(Environment.OSVersion.ToString()); #endif #endif // NETSTANDARD1_3 sb.Append(")"); return(sb.ToString()); }
public static string TestAssemblyLocationInfoMethod() { #if NETSTANDARD2_0 return(SystemInfo.AssemblyLocationInfo(typeof(SystemInfoTest).GetTypeInfo().Assembly)); #else return(SystemInfo.AssemblyLocationInfo(Assembly.GetCallingAssembly())); #endif }
private static string GetVersionInfo() { StringBuilder builder = new StringBuilder(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); builder.Append("log4net assembly [").Append(executingAssembly.FullName).Append("]. "); builder.Append("Loaded from [").Append(SystemInfo.AssemblyLocationInfo(executingAssembly)).Append("]. "); builder.Append("(.NET Runtime [").Append(Environment.Version.ToString()).Append("]"); builder.Append(" on ").Append(Environment.OSVersion.ToString()); builder.Append(")"); return(builder.ToString()); }
/// <summary> /// Internal method to get pertinent version info. /// </summary> /// <returns>A string of version info.</returns> private static string GetVersionInfo() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); // Grab the currently executing assembly Assembly myAssembly = Assembly.GetExecutingAssembly(); // Build Up message sb.Append("log4net assembly [").Append(myAssembly.FullName).Append("]. "); sb.Append("Loaded from [").Append(SystemInfo.AssemblyLocationInfo(myAssembly)).Append("]. "); sb.Append("(.NET Runtime [").Append(Environment.Version.ToString()).Append("]"); sb.Append(" on ").Append(Environment.OSVersion.ToString()); sb.Append(")"); return(sb.ToString()); }
/// <summary> /// Gets the repository name and repository type for the specified assembly. /// </summary> /// <param name="assembly">The assembly that has a <see cref="log4net.Config.RepositoryAttribute"/>.</param> /// <param name="repositoryName">in/out param to hold the repository name to use for the assembly, caller should set this to the default value before calling.</param> /// <param name="repositoryType">in/out param to hold the type of the repository to create for the assembly, caller should set this to the default value before calling.</param> /// <exception cref="ArgumentNullException"><paramref name="assembly" /> is <see langword="null" />.</exception> private void GetInfoForAssembly(Assembly assembly, ref string repositoryName, ref Type repositoryType) { if (assembly == null) { throw new ArgumentNullException("assembly"); } try { LogLog.Debug(declaringType, "Assembly [" + assembly.FullName + "] Loaded From [" + SystemInfo.AssemblyLocationInfo(assembly) + "]"); } catch { // Ignore exception from debug call } try { // Look for the RepositoryAttribute on the assembly object[] repositoryAttributes = Attribute.GetCustomAttributes(assembly, typeof(log4net.Config.RepositoryAttribute), false); if (repositoryAttributes == null || repositoryAttributes.Length == 0) { // This is not a problem, but its nice to know what is going on. LogLog.Debug(declaringType, "Assembly [" + assembly + "] does not have a RepositoryAttribute specified."); } else { if (repositoryAttributes.Length > 1) { LogLog.Error(declaringType, "Assembly [" + assembly + "] has multiple log4net.Config.RepositoryAttribute assembly attributes. Only using first occurrence."); } log4net.Config.RepositoryAttribute domAttr = repositoryAttributes[0] as log4net.Config.RepositoryAttribute; if (domAttr == null) { LogLog.Error(declaringType, "Assembly [" + assembly + "] has a RepositoryAttribute but it does not!."); } else { // If the Name property is set then override the default if (domAttr.Name != null) { repositoryName = domAttr.Name; } // If the RepositoryType property is set then override the default if (domAttr.RepositoryType != null) { // Check that the type is a repository if (typeof(ILoggerRepository).IsAssignableFrom(domAttr.RepositoryType)) { repositoryType = domAttr.RepositoryType; } else { LogLog.Error(declaringType, "DefaultRepositorySelector: Repository Type [" + domAttr.RepositoryType + "] must implement the ILoggerRepository interface."); } } } } } catch (Exception ex) { LogLog.Error(declaringType, "Unhandled exception in GetInfoForAssembly", ex); } }
public static string TestAssemblyLocationInfoMethod() { return(SystemInfo.AssemblyLocationInfo(Assembly.GetCallingAssembly())); }
/// <summary> /// Gets the repository name and repository type for the specified assembly. /// </summary> /// <param name="assembly">The assembly that has a <see cref="T:log4net.Config.RepositoryAttribute" />.</param> /// <param name="repositoryName">in/out param to hold the repository name to use for the assembly, caller should set this to the default value before calling.</param> /// <param name="repositoryType">in/out param to hold the type of the repository to create for the assembly, caller should set this to the default value before calling.</param> /// <exception cref="T:System.ArgumentNullException"><paramref name="assembly" /> is <see langword="null" />.</exception> private void GetInfoForAssembly(Assembly assembly, ref string repositoryName, ref Type repositoryType) { if ((object)assembly == null) { throw new ArgumentNullException("assembly"); } try { LogLog.Debug(declaringType, "Assembly [" + assembly.FullName + "] Loaded From [" + SystemInfo.AssemblyLocationInfo(assembly) + "]"); } catch { } try { object[] array = assembly.GetCustomAttributes(typeof(RepositoryAttribute)).ToArray(); if (array == null || array.Length == 0) { LogLog.Debug(declaringType, "Assembly [" + assembly + "] does not have a RepositoryAttribute specified."); } else { if (array.Length > 1) { LogLog.Error(declaringType, "Assembly [" + assembly + "] has multiple log4net.Config.RepositoryAttribute assembly attributes. Only using first occurrence."); } RepositoryAttribute repositoryAttribute = array[0] as RepositoryAttribute; if (repositoryAttribute == null) { LogLog.Error(declaringType, "Assembly [" + assembly + "] has a RepositoryAttribute but it does not!."); } else { if (repositoryAttribute.Name != null) { repositoryName = repositoryAttribute.Name; } if ((object)repositoryAttribute.RepositoryType != null) { if (CompatibilityExtensions.IsAssignableFrom(typeof(ILoggerRepository), repositoryAttribute.RepositoryType)) { repositoryType = repositoryAttribute.RepositoryType; } else { LogLog.Error(declaringType, "DefaultRepositorySelector: Repository Type [" + repositoryAttribute.RepositoryType + "] must implement the ILoggerRepository interface."); } } } } } catch (Exception exception) { LogLog.Error(declaringType, "Unhandled exception in GetInfoForAssembly", exception); } }