protected override void RegisterTypes(IContainerRegistry containerRegistry) { #region Log var config = new NLog.Config.LoggingConfiguration(); var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "log/file.txt" }; config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logfile); NLog.LogManager.Configuration = config; var factory = new NLog.Extensions.Logging.NLogLoggerFactory(); Microsoft.Extensions.Logging.ILogger logger = factory.CreateLogger(""); containerRegistry.RegisterInstance <Microsoft.Extensions.Logging.ILogger>(logger); var log = Container.Resolve <Microsoft.Extensions.Logging.ILogger>(); log.LogInformation("Test in RegisterTypes"); #endregion //containerRegistry.RegisterInstance(typeof(ILocalizerService), // "LocalizerService", // new LocalizerService("zh-TW"), // new ContainerControlledLifetimeManager()); //containerRegistry.RegisterInstance<ILocalizerService, LocalizerService("zh-TW")>(new ContainerControlledLifetimeManager()); containerRegistry.RegisterSingleton <ILocalizerService, LocalizerService>(); containerRegistry.RegisterSingleton <IMessageService, MessageService>(); containerRegistry.RegisterSingleton <IApplicationCommands, ApplicationCommandsProxy>(); containerRegistry.RegisterInstance <IFlyoutService>(Container.Resolve <FlyoutService>()); }
static Boolean InitLogsWithNLog() { String logConfigFilePath = @"..\..\NLogConfiguration.xml"; // File path to log configuration (or you could alos use an embedded resource) try { if (File.Exists(logConfigFilePath)) { // Get content of the log file configuration String logConfigContent = File.ReadAllText(logConfigFilePath, System.Text.Encoding.UTF8); // Create NLog configuration using XML file content XmlLoggingConfiguration config = XmlLoggingConfiguration.CreateFromXmlString(logConfigContent); if (config.InitializeSucceeded == true) { // Set NLog configuration NLog.LogManager.Configuration = config; // Create Logger factory var factory = new NLog.Extensions.Logging.NLogLoggerFactory(); // Set Logger factory to Rainbow SDK Rainbow.LogFactory.Set(factory); return(true); } } } catch { } return(false); }
public GenericLogger() { var lg = new NLog.Extensions.Logging.NLogLoggerFactory(); var lgg = lg.CreateLogger(""); _logger = lgg; }
static Boolean InitLogsWithNLog() { try { Stream stream = Helper.GetMemoryStreamFromResource("NLogConfiguration.xml"); String logConfigContent = null; using (StreamReader sr = new StreamReader(stream)) { logConfigContent = sr.ReadToEnd(); } stream.Dispose(); // Create NLog configuration using XML file content XmlLoggingConfiguration config = XmlLoggingConfiguration.CreateFromXmlString(logConfigContent); if (config.InitializeSucceeded == true) { // Set NLog configuration NLog.LogManager.Configuration = config; // Create Logger factory var factory = new NLog.Extensions.Logging.NLogLoggerFactory(); // Set Logger factory to Rainbow SDK Rainbow.LogFactory.Set(factory); return(true); } } catch { } return(false); }
static Boolean InitLogsWithNLog() { try { String logConfigContent = WpfUtil.GetContentFromResource("NLogConfiguration.xml"); // Create NLog configuration using XML file content XmlLoggingConfiguration config = XmlLoggingConfiguration.CreateFromXmlString(logConfigContent); if (config.InitializeSucceeded == true) { // Set NLog configuration NLog.LogManager.Configuration = config; // Create Logger factory var factory = new NLog.Extensions.Logging.NLogLoggerFactory(); // Set Logger factory to Rainbow SDK Rainbow.LogFactory.Set(factory); return(true); } } catch { } return(false); }
static Boolean InitLogsWithNLog(String folder) { String logConfigFileName = "NLogConfiguration.xml"; String logFileName = "MultiPlatformApplication"; // File name of the log file String suffixWebRtc = "_WebRTC"; String suffixArchive = "_{###}"; String extension = ".log"; try { // Get content of the log file configuration String logConfigContent = Helper.GetContentOfEmbeddedResource(logConfigFileName, Encoding.UTF8); // Load XML in XMLDocument XmlDocument doc = new XmlDocument(); doc.LoadXml(logConfigContent); XmlElement targetElement = doc["nlog"]["targets"]; var targetsList = targetElement.ChildNodes; foreach (var target in targetsList) { if (target is XmlElement xmlElement) { var name = xmlElement.GetAttribute("name"); if (name?.Contains("WEBRTC") == true) { var filename = Path.Combine(folder, logFileName + suffixWebRtc + extension); var archiveFilename = Path.Combine(folder, logFileName + suffixWebRtc + suffixArchive + extension); xmlElement.SetAttribute("fileName", filename); xmlElement.SetAttribute("archiveFileName", archiveFilename); } else { var filename = Path.Combine(folder, logFileName + extension); var archiveFilename = Path.Combine(folder, logFileName + suffixArchive + extension); xmlElement.SetAttribute("fileName", filename); xmlElement.SetAttribute("archiveFileName", archiveFilename); } } } // Create NLog configuration using XML file content XmlLoggingConfiguration config = XmlLoggingConfiguration.CreateFromXmlString(doc.OuterXml); if (config.InitializeSucceeded == true) { // Set NLog configuration NLog.LogManager.Configuration = config; // Create Logger factory var factory = new NLog.Extensions.Logging.NLogLoggerFactory(); // Set Logger factory to Rainbow SDK Rainbow.LogFactory.Set(factory); return(true); } } catch { } return(false); }