protected override LoggingConfiguration SetupLogging(EndpointConfiguration endpointConfiguration) { var logDir = ".\\logfiles\\"; Directory.CreateDirectory(logDir); var logFile = Path.Combine(logDir, endpointConfiguration.EndpointName + ".txt"); if (File.Exists(logFile)) { File.Delete(logFile); } var logLevel = "ERROR"; var nlogConfig = new LoggingConfiguration(); var fileTarget = new FileTarget { FileName = logFile, }; nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Warn, fileTarget) { Final = true }); nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.FromString(logLevel), fileTarget)); nlogConfig.LoggingRules.Add(new LoggingRule("ServiceControl.ExternalIntegrations.*", LogLevel.Debug, fileTarget)); nlogConfig.AddTarget("debugger", fileTarget); NLogConfigurator.Configure(new object[] { fileTarget }, logLevel); return(nlogConfig); }
protected void SetupNLog(LogLevel logLevel) { var nLogViewerTarget = GetNLogViewerLoggingTarget(); var consoleTarget = GetConsoleLoggingTarget(); NLogConfigurator.Configure(new object[] { nLogViewerTarget, consoleTarget }, logLevel.ToString()); }
static void SetupLogging(EndpointConfiguration endpointConfiguration) { var logDir = ".\\logfiles\\"; Directory.CreateDirectory(logDir); var logFile = Path.Combine(logDir, endpointConfiguration.EndpointName + ".txt"); if (File.Exists(logFile)) { File.Delete(logFile); } var logLevel = "INFO"; var nlogConfig = new LoggingConfiguration(); var fileTarget = new FileTarget { FileName = logFile, }; nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.FromString(logLevel), fileTarget)); nlogConfig.AddTarget("debugger", fileTarget); NLogConfigurator.Configure(new object[] { fileTarget }, logLevel); LogManager.Configuration = nlogConfig; }
public static Configure NLog(this Configure config, params object[] targetsForNServiceBusToLogTo) { if (targetsForNServiceBusToLogTo == null) { throw new ArgumentNullException("targetsForNServiceBusToLogTo"); } if (targetsForNServiceBusToLogTo.Length == 0) { throw new ArgumentException("Must not be empty.", "targetsForNServiceBusToLogTo"); } if (targetsForNServiceBusToLogTo.Any(x => x == null)) { throw new ArgumentNullException("targetsForNServiceBusToLogTo", "Must not contain null values."); } string threshold = null; var cfg = Configure.GetConfigSection <Config.Logging>(); if (cfg != null) { threshold = cfg.Threshold; } NLogConfigurator.Configure(targetsForNServiceBusToLogTo, threshold); return(config); }
public void Threshold_should_be_All() { new ColoredConsoleTarget() { UseDefaultRowHighlightingRules = true }; var filename = "logfile"; NLog.Config.SimpleConfigurator.ConfigureForConsoleLogging(); //LoggingConfiguration config = new LoggingConfiguration(); //LoggingRule rule = new LoggingRule("*", minLevel, consoleTarget); //config.LoggingRules.Add(rule); //NLog.LogManager.Configuration = config; new NLog.Config.LoggingConfiguration(); new FileTarget() { FileName = Layout.FromString(filename), ArchiveFileName = string.Format("{0}.{{#}}", filename), ArchiveAboveSize = 1024 * 1024, ArchiveEvery = FileArchivePeriod.Day, ArchiveNumbering = ArchiveNumberingMode.Rolling, MaxArchiveFiles = 10, KeepFileOpen = false }; NLogConfigurator.Configure(new ConsoleTarget(), "Debug"); LogManager.GetLogger("Test").Debug("Testing Debug"); }
public void Threshold_default_should_be_Info() { NLogConfigurator.Configure(new ConsoleTarget()); LogManager.GetLogger("Test").Debug("Testing Debug"); LogManager.GetLogger("Test").Info("Testing Info"); }
public void Start(IProject context, IBehavior behavior) { var configurator = new NLogConfigurator(); configurator.Configure(); try { List <string> newOnlineVariables = new List <string>(); // iterate through all variables in the current project and select all variables which are marked as "External Visible" foreach (var item in context.VariableCollection) { if ((bool)item.GetDynamicProperty("ExternVisible")) { newOnlineVariables.Add(item.Name); } } if (newOnlineVariables.Any()) { _variableSubscription.Start(context, newOnlineVariables); } else { Logger.Info("No Variables in the project " + context.Name + " were marked as \"External Visible\""); } } catch (Exception exception) { Logger.Error(exception); } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions <LogOptions> options) { var loggerFactory = app.ApplicationServices.GetRequiredService <ILoggerFactory>(); loggerFactory.AddNLog(); loggerFactory.ConfigureNLog(NLogConfigurator.Configure(options)); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler(AppDefaults.ERROR_DEFAULT_PATH); } var locOptions = app.ApplicationServices.GetService <IOptions <RequestLocalizationOptions> >(); app.UseRequestLocalization(locOptions.Value); app.UseStaticFiles(); app.UseIdentity(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Weather}/{action=Index}/{id?}"); }); this.DatabaseInitialize(app.ApplicationServices).Wait(); }
public void Can_create_RollingFileTarget() { var target = NLogTargetFactory.CreateRollingFileTarget("nlog.txt"); NLogConfigurator.Configure(target, "Debug"); NLog.LogManager.GetCurrentClassLogger().Debug("Testing rolling file target"); }
public void Can_create_ConsoleTarget() { var target = NLogTargetFactory.CreateColoredConsoleTarget(); NLogConfigurator.Configure(target, "Debug"); NLog.LogManager.GetCurrentClassLogger().Debug("Testing console target"); }
public void Can_configure_2_targets() { NLogConfigurator.Configure(new Target[] { new ConsoleTarget(), new ColoredConsoleTarget() }); var loggingConfiguration = NLog.LogManager.Configuration; Assert.AreEqual(2, loggingConfiguration.LoggingRules[0].Targets.Count); }
public Log(IEditorApplication editorApplication, string driverIdent) { var configurator = new NLogConfigurator(); configurator.Configure(); _editorApplication = editorApplication; _driverApiName = driverIdent + "API"; }
public void Can_create_ColoredConsoleTarget() { var target = NLogTargetFactory.CreateColoredConsoleTarget("${longdate}|${level:uppercase=true}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}"); NLogConfigurator.Configure(target, "Debug"); NLog.LogManager.GetCurrentClassLogger().Debug("Testing colored console target"); NLog.LogManager.GetCurrentClassLogger().DebugException("Testing colored console target", new Exception()); }
static void ConfigureLogging() { if (LogManager.Configuration != null) { return; } var nlogConfig = new LoggingConfiguration(); var simpleLayout = new SimpleLayout("${longdate}|${threadid}|${level}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}"); var fileTarget = new FileTarget { ArchiveEvery = FileArchivePeriod.Day, FileName = Path.Combine(Settings.LogPath, "logfile.txt"), ArchiveFileName = Path.Combine(Settings.LogPath, "log.{#}.txt"), ArchiveNumbering = ArchiveNumberingMode.Rolling, Layout = simpleLayout, MaxArchiveFiles = 14, }; var consoleTarget = new ColoredConsoleTarget { Layout = simpleLayout, UseDefaultRowHighlightingRules = true, }; nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Error, fileTarget)); nlogConfig.LoggingRules.Add(new LoggingRule("Raven.*", LogLevel.Error, consoleTarget) { Final = true }); nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.RavenDB.Persistence.*", LogLevel.Error, fileTarget) { Final = true }); nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.Licensing.*", LogLevel.Error, fileTarget) { Final = true }); nlogConfig.LoggingRules.Add(new LoggingRule("NServiceBus.Licensing.*", LogLevel.Error, consoleTarget) { Final = true }); nlogConfig.LoggingRules.Add(new LoggingRule("Particular.ServiceControl.Licensing.*", LogLevel.Info, fileTarget)); nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, fileTarget)); nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget)); nlogConfig.AddTarget("debugger", fileTarget); nlogConfig.AddTarget("console", consoleTarget); NLogConfigurator.Configure(new object[] { fileTarget, consoleTarget }, "Info"); LogManager.Configuration = nlogConfig; }
public void InCode() { #region NLogInCode var config = new LoggingConfiguration(); var consoleTarget = new ColoredConsoleTarget { Layout = "${level:uppercase=true}|${logger}|${message}${onexception:${newline}${exception:format=tostring}}" }; config.AddTarget("console", consoleTarget); config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, consoleTarget)); LogManager.Configuration = config; NLogConfigurator.Configure(); #endregion }
public void Start(IProject context, IBehavior behavior) { var configurator = new NLogConfigurator(); configurator.Configure(); project = context; if (context == null) { Logger.Error($"no project available. Service '{Assembly.GetExecutingAssembly().GetName()}' cannot be started."); return; } context.ScreenCollection.ElementLeftButtonDoubleClick += ScreenCollection_ElementLeftButtonDoubleClick; context.ScreenCollection.ElementLeftButtonDown += ScreenCollection_ElementLeftButtonDown; context.ScreenCollection.ElementLeftButtonUp += ScreenCollection_ElementLeftButtonUp; context.ScreenCollection.ElementMouseOver += ScreenCollection_ElementMouseOver; context.ScreenCollection.ElementRightButtonDoubleClick += ScreenCollection_ElementRightButtonDoubleClick; context.ScreenCollection.ElementRightButtonDown += ScreenCollection_ElementRightButtonDown; context.ScreenCollection.ElementRightButtonUp += ScreenCollection_ElementRightButtonUp; Logger.Info(DateTime.Now + "\tService start!"); }
public void Init() { var nlogConfig = new LoggingConfiguration(); var fileTarget = new FileTarget { ArchiveEvery = FileArchivePeriod.Day, FileName = "${specialfolder:folder=ApplicationData}/ServiceBus.Management/logs/logfile.txt", ArchiveFileName = "${specialfolder:folder=ApplicationData}/ServiceBus.Management/logs/log.{#}.txt", ArchiveNumbering = ArchiveNumberingMode.Rolling, MaxArchiveFiles = 14 }; var consoleTarget = new ColoredConsoleTarget { UseDefaultRowHighlightingRules = true, }; nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, fileTarget)); nlogConfig.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget)); nlogConfig.AddTarget("debugger", fileTarget); nlogConfig.AddTarget("console", consoleTarget); NLogConfigurator.Configure(new object[] { fileTarget, consoleTarget }, "Info"); LogManager.Configuration = nlogConfig; var transportType = SettingsReader <string> .Read("TransportType", typeof(Msmq).AssemblyQualifiedName); Configure.With().UseTransport(Type.GetType(transportType)); using (var licenseStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ServiceBus.Management.License.xml")) using (var sr = new StreamReader(licenseStream)) { Configure.Instance.License(sr.ReadToEnd()); } Configure.Transactions.Advanced(t => t.DisableDistributedTransactions()); }
public static void PostStart() { NLogConfigurator.Configure(); ConfigCommonLogging(); ConfigJSNLogRoutes(); }
public static void NLog() { NLogConfigurator.Configure(); }