private ILog GetLog4NetLogger() { BasicConfigurator.Configure(); // from https://stackoverflow.com/questions/16336917/can-you-configure-log4net-in-code-instead-of-using-a-config-file var hierarchy = (Hierarchy)LogManager.GetRepository(); hierarchy.ResetConfiguration(); hierarchy.Clear(); var patternLayout = new PatternLayout(); patternLayout.ConversionPattern = "%date [%thread] %-5level %logger %message%newline"; patternLayout.ActivateOptions(); var roller = new RollingFileAppender(); roller.AppendToFile = false; roller.File = $"{_logsFolder}/log4net.txt"; roller.Layout = patternLayout; roller.ImmediateFlush = true; roller.RollingStyle = RollingFileAppender.RollingMode.Once; roller.MaxFileSize = 128 * 1000 * 1000; roller.ActivateOptions(); hierarchy.Threshold = Level.Info; hierarchy.Root.Level = Level.Info; hierarchy.Root.AddAppender(roller); hierarchy.Configured = true; return(LogManager.GetLogger(GetType())); }
private static void InitLog4Net() { XmlConfigurator.ConfigureAndWatch( new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config"))); _log4NetKeepFalse = LogManager.GetLogger("keepfalse"); _log4NetKeepTrue = LogManager.GetLogger("keeptrue"); }
private void ConfigurateLogging() { Uri configUri = new Uri($"{AppDomain.CurrentDomain.BaseDirectory}config/logconfig.xml"); if (!File.Exists(configUri.OriginalString)) { throw new ConfigNotExistsException($"configuration file not found at: {configUri.AbsolutePath}"); } XmlConfigurator.Configure(configUri); LogManager.GetLogger(typeof(Bootstrapper)).Info("Logging configurated in Bootstrapper"); }
public HttpConfiguration Build() { var logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); var commonLogger = new CodeConfigurableLog4NetLogger(logger); IList <Func <string, ScriptClass> > typeStrategies = new List <Func <string, ScriptClass> >(_typeStrategies); var services = new ScriptServicesBuilder(new ScriptConsole(), commonLogger). FilePreProcessor <WebApiFilePreProcessor>().Build(); var preProcessor = (WebApiFilePreProcessor)services.FilePreProcessor; typeStrategies.Add(ControllerStategy); preProcessor.SetClassStrategies(typeStrategies); preProcessor.LoadSharedCode(Path.Combine(_scriptsPath, "Shared")); ProcessScripts(services); return(_configuration); }
public void Initialize() { if (!initialized) { initialized = true; } else { return; } if (File.Exists("Log.txt")) { File.Delete("Log.txt"); } logWriter = File.CreateText("Log.txt"); logBuilder = new StringBuilder(); logger = LogglyManager.GetLogger("ConfigEditor"); }
public ClipboardViewModel(IEventAggregator eventAggregator, ClipboardRepo clipboardRepo) { _logger = LogManager.GetLogger("ClipboardViewModel"); _eventAggregator = eventAggregator; _clipboardRepo = clipboardRepo; _eventAggregator.Subscribe(this); DisplayName = "Clipboard"; ClipboardItems = new BindableCollection <ClipboardItemViewModel>(); _masterList = new List <ClipboardItemViewModel>(); HideStateMsg = false; var clipboardItems = LoadClipboardItems(); _masterList.AddRange(clipboardItems); SafeAddToClipboardHistory(BuildViewModelFromClipboard()); RebuildClipboardItems(); HideStateMsg = true; }
/// <summary> /// Gets the Logger and overgive a filename /// </summary> /// <param name="filename"></param> /// <returns></returns> public static ILog GetLogger([CallerFilePath] string filename = "") { return(LogManager.GetLogger(filename)); }
private static bool Init() { bool go; lock (log4net_loaded_lock) { go = (null == __log && log4net_loaded && !log4net_init_pending && !log4net_has_shutdown); if (go) { log4net_init_pending = true; // block simultaneous execution of the rest of the code in Init() } } if (go) { try { BasicConfigurator.Configure(); XmlConfigurator.Configure(); ILog l = LogManager.GetLogger(typeof(Logging)); lock (log4net_loaded_lock) { __log = l; } // as per https://stackoverflow.com/questions/28723920/check-whether-log4net-xmlconfigurator-succeeded // // log4net must have picked up the configuration or it will not function anyhow //if (!LogManager.GetRepository().Configured) { // log4net not configured foreach (var message in LogManager.GetRepository().ConfigurationMessages) { // evaluate configuration message LogLog logInitMsg = message as LogLog; BufferMessage(String.Format("log4net config: {0}", logInitMsg?.Message ?? message)); } } } catch (Exception ex) { BufferException(ex); } } bool rv; lock (log4net_loaded_lock) { if (go) { log4net_init_pending = false; // de-block } // return value: TRUE when success rv = (null != __log); } // only log/yak about initialization success when it actually did happen just above: if (rv) { Debug("Logging initialised at {0}", LogAssist.AppendStackTrace(null, "get_log")); Info("Logging initialised."); // thread safety: move and reset the pending message buffer/list List <LogBufEntry> lst = new List <LogBufEntry>(); lock (log4net_loaded_lock) { if (init_ex_list != null && init_ex_list.Count > 0) { // move list lst = init_ex_list; init_ex_list = null; } } if (lst.Count > 0) { Error("--- Logging early bird log messages: ---"); foreach (LogBufEntry ex in lst) { if (ex.ex != null) { if (ex.message != null) { Error(ex.ex, "{0}", ex.message); } else { Error(ex.ex, "Logger init failure?"); } } else { Info("{0}", ex.message); } } lst.Clear(); Error("-- Logging early bird log messages done. ---"); } } return(rv); }
//static Log4netLogFactory() //{ // // load the log4net configuration from the application configuration. // XmlConfigurator.Configure(); //} public ILog GetLog(string name) { return(new Log4netLog(LogManager.GetLogger(name))); }
public override void Load() { this.Bind <ILog>().ToMethod(context => LogManagerLog4net.GetLogger(context.Request.Target.Member.ReflectedType)); this.Bind(typeof(IRepository <>)).To(typeof(Repository <>)); }
public LoggerControl() { Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Dblog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Logger = NLog.LogManager.GetCurrentClassLogger(); }
public ILogger LoggerFor(Type type) { return(GetLogger(LogManager.GetLogger(type))); }
public ILogger Create(string name) { return(new Log4NetLogger(LogManager.GetLogger(name))); }
public ILogger Create(Type type) { return(new Log4NetLogger(LogManager.GetLogger(type))); }
public ILogger Create <T>() { return(new Log4NetLogger(LogManager.GetLogger(typeof(T)))); }