/// <summary>Setups the cache subscriber.</summary> /// <autogeneratedoc /> /// TODO Edit XML Comment Template for SetupCacheSubscriber // ReSharper disable once UnusedMember.Global public static void SetupCacheSubscriber( ) { var myCacheTarget = MyCacheTarget.GetInstance(1000); myCacheTarget.Cache.SubscribeOn(Scheduler.Default) .Buffer(TimeSpan.FromMilliseconds(100)) .Where(x => x.Any( )) .ObserveOnDispatcher(DispatcherPriority.Background) .Subscribe( infos => { // ReSharper disable once UnusedVariable foreach (var logEventInfo in infos) { } } ); }
internal static void ConfigureLogging( LogDelegates.LogMethod logMethod , bool proxyLogging = false ) { // logMethod ( // Resource // .AppLoggingConfigHelper_ConfigureLogging_____Starting_logger_configuration_ // ) ; LogFactory proxiedFactory = null; if (proxyLogging) { var proxyGenerator = new ProxyGenerator(); var loggerProxyHelper = new LoggerProxyHelper(proxyGenerator, DoLogMessage); var logFactory = new MyLogFactory(DoLogMessage); var lConfLogFactory = loggerProxyHelper.CreateLogFactory(logFactory); proxiedFactory = lConfLogFactory; } var fieldInfo = typeof(LogManager).GetField( "factory" , BindingFlags.Static | BindingFlags.NonPublic ); if (fieldInfo != null) { logMethod($"field info is {fieldInfo.DeclaringType} . {fieldInfo.Name}"); var cur = fieldInfo.GetValue(null); logMethod($"cur is {cur}"); if (proxyLogging) { fieldInfo.SetValue(null, proxiedFactory); var newVal = fieldInfo.GetValue(null); logMethod($"New Value = {newVal}"); } } // var useFactory = proxyLogging ? proxiedFactory : LogManager.LogFactory; var lConf = new CodeConfiguration(); var dict = LogLevel.AllLoggingLevels.ToDictionary( level => level , level => new List <Target>() ); var errorTargets = dict[LogLevel.Error]; var t = dict[LogLevel.Trace]; // var x = new EventLogTarget("eventLog") { Source = "Application Error" }; // errorTargets.Add(x); var webServiceTarget = new LogReceiverWebServiceTarget("log"); webServiceTarget.EndpointAddress = "http://xx1.mynetgear.com/LogService/ReceiveLogs.svc";// "http://localhost:27809/ReceiveLogs.svc"; // webServiceTarget.EndpointConfigurationName = "log"; dict[LogLevel.Debug].Add(webServiceTarget); #region Cache Target #if false var cacheTarget = new MyCacheTarget( ); t.Add(cacheTarget); #endif #endregion #region NLogViewer Target var viewer = Viewer(); t.Add(viewer); #endregion #region Debugger Target if (DebuggerTargetEnabled) { var debuggerTarget = new DebuggerTarget { Layout = new SimpleLayout("${message}") }; t.Add(debuggerTarget); } #endregion #region Chainsaw Target var chainsawTarget = new ChainsawTarget( ); SetupNetworkTarget(chainsawTarget, "udp://xx1.mynetgear.com:4445"); t.Add(chainsawTarget); #endregion t.Add(MyFileTarget()); var jsonFileTarget = JsonFileTarget(); t.Add(jsonFileTarget); var byType = new Dictionary <Type, int>(); foreach (var target in dict.SelectMany(pair => pair.Value)) { var type = target.GetType(); byType.TryGetValue(type, out var count); count += 1; byType[type] = count; if (target.Name == null) { target.Name = $"{Regex.Replace(type.Name, "Target", "")}{count:D2}"; } lConf.AddTarget(target); } foreach (var result in dict.Select(LoggingRule)) { ((List <LoggingRule>)lConf.LoggingRules).AddRange(result); } LogManager.Configuration = lConf; Logger = LogManager.GetCurrentClassLogger(); }