private void OnWatcherError(object source, ErrorEventArgs e) { var watcherPath = string.Empty; var watcher = source as FileSystemWatcher; if (watcher != null) { watcherPath = watcher.Path; } var exception = e.GetException(); if (exception != null) { InternalLogger.Warn(exception, "Error Watching Path {0}", watcherPath); } else { InternalLogger.Warn("Error Watching Path {0}", watcherPath); } }
/// <summary> /// Load from url /// </summary> /// <param name="assemblyFileName">file or path, including .dll</param> /// <param name="baseDirectory">basepath, optional</param> /// <returns></returns> public static Assembly LoadFromPath(string assemblyFileName, string baseDirectory = null) { string fullFileName = baseDirectory == null ? assemblyFileName : Path.Combine(baseDirectory, assemblyFileName); InternalLogger.Info("Loading assembly file: {0}", fullFileName); #if NETSTANDARD1_5 try { var assemblyName = System.Runtime.Loader.AssemblyLoadContext.GetAssemblyName(fullFileName); return(Assembly.Load(assemblyName)); } catch (Exception ex) { // this doesn't usually work InternalLogger.Warn(ex, "Fallback to AssemblyLoadContext.Default.LoadFromAssemblyPath for file: {0}", fullFileName); return(System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(fullFileName)); } #else Assembly asm = Assembly.LoadFrom(fullFileName); return(asm); #endif }
/// <summary> /// Render the event info as parse as <c>bool</c> /// </summary> /// <param name="layout">current layout</param> /// <param name="logEvent"></param> /// <param name="defaultValue">default value when the render </param> /// <param name="layoutName">layout name for log message to internal log when logging fails</param> /// <returns></returns> public static bool RenderBool(this Layout layout, LogEventInfo logEvent, bool defaultValue, string layoutName) { if (layout == null) { InternalLogger.Debug(layoutName + " is null so default value of " + defaultValue); return(defaultValue); } if (logEvent == null) { InternalLogger.Debug(layoutName + ": logEvent is null so default value of " + defaultValue); return(defaultValue); } var rendered = layout.Render(logEvent); bool result; if (!bool.TryParse(rendered, out result)) { InternalLogger.Warn(layoutName + ": parse of value '" + rendered + "' failed, return " + defaultValue); return(defaultValue); } return(result); }
internal void Watch(string fileName) { var directory = Path.GetDirectoryName(fileName); if (!Directory.Exists(directory)) { InternalLogger.Warn("Cannot watch {0} for changes as it doesn't exist", directory); return; } lock (this) { if (_watcherMap.ContainsKey(fileName)) { return; } var watcher = new FileSystemWatcher { Path = directory, Filter = Path.GetFileName(fileName), NotifyFilter = NotifyFilters }; watcher.Created += OnFileChanged; watcher.Changed += OnFileChanged; watcher.Deleted += OnFileChanged; watcher.Renamed += OnFileChanged; watcher.Error += OnWatcherError; watcher.EnableRaisingEvents = true; InternalLogger.Debug("Watching path '{0}' filter '{1}' for changes.", watcher.Path, watcher.Filter); _watcherMap.Add(fileName, watcher); } }
public static string GetAssemblyFileLocation(Assembly assembly) { string fullName = string.Empty; try { if (assembly == null) { return(string.Empty); } fullName = assembly.FullName; #if NETSTANDARD if (string.IsNullOrEmpty(assembly.Location)) { // Assembly with no actual location should be skipped (Avoid PlatformNotSupportedException) InternalLogger.Warn("Ignoring assembly location because location is empty: {0}", fullName); return(string.Empty); } #endif Uri assemblyCodeBase; if (!Uri.TryCreate(assembly.CodeBase, UriKind.RelativeOrAbsolute, out assemblyCodeBase)) { InternalLogger.Warn("Ignoring assembly location because code base is unknown: '{0}' ({1})", assembly.CodeBase, fullName); return(string.Empty); } var assemblyLocation = Path.GetDirectoryName(assemblyCodeBase.LocalPath); if (string.IsNullOrEmpty(assemblyLocation)) { InternalLogger.Warn("Ignoring assembly location because it is not a valid directory: '{0}' ({1})", assemblyCodeBase.LocalPath, fullName); return(string.Empty); } DirectoryInfo directoryInfo = new DirectoryInfo(assemblyLocation); if (!directoryInfo.Exists) { InternalLogger.Warn("Ignoring assembly location because directory doesn't exists: '{0}' ({1})", assemblyLocation, fullName); return(string.Empty); } InternalLogger.Debug("Found assembly location directory: '{0}' ({1})", directoryInfo.FullName, fullName); return(directoryInfo.FullName); } catch (System.PlatformNotSupportedException ex) { InternalLogger.Warn(ex, "Ignoring assembly location because assembly lookup is not supported: {0}", fullName); if (ex.MustBeRethrown()) { throw; } return(string.Empty); } catch (System.Security.SecurityException ex) { InternalLogger.Warn(ex, "Ignoring assembly location because assembly lookup is not allowed: {0}", fullName); if (ex.MustBeRethrown()) { throw; } return(string.Empty); } catch (UnauthorizedAccessException ex) { InternalLogger.Warn(ex, "Ignoring assembly location because assembly lookup is not allowed: {0}", fullName); if (ex.MustBeRethrown()) { throw; } return(string.Empty); } }