How to roll the log file on startup in logback

None of the other suggestions was appropriate for my situation. I didn’t want to use a size-and-time-based solution, because it requires configuring a MaxFileSize, and we are using a strictly time-based policy. Here is how I accomplished rolling the file on startup with a TimeBasedRollingPolicy: @NoAutoStart public class StartupTimeBasedTriggeringPolicy<E> extends DefaultTimeBasedFileNamingAndTriggeringPolicy<E> { @Override public void … Read more

Actually read AppSettings in ConfigureServices phase in ASP.NET Core

That is the way you can get the typed settings from appSettings.json right in ConfigureServices method: public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.Configure<MySettings>(Configuration.GetSection(nameof(MySettings))); services.AddSingleton(Configuration); // … var settings = Configuration.GetSection(nameof(MySettings)).Get<MySettings>(); int maxNumberOfSomething = settings.MaxNumberOfSomething; // … } // … Read more

Is there a way to run a method/class only on Tomcat/Wildfly/Glassfish startup?

You could write a ServletContextListener which calls your method from the contextInitialized() method. You attach the listener to your webapp in web.xml, e.g. <listener> <listener-class>my.Listener</listener-class> </listener> and package my; public class Listener implements javax.servlet.ServletContextListener { public void contextInitialized(ServletContext context) { MyOtherClass.callMe(); } } Strictly speaking, this is only run once on webapp startup, rather than … Read more

windows service startup timeout

I agree with Romulo on finishing to start your service as soon as possible. However, if you need the time and you are using .NET Framework 2.0 or later, you might consider ServiceBase.RequestAdditionalTime() method. http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.requestadditionaltime.aspx protected override void OnStart() { this.RequestAdditionalTime(10000); // do your stuff }

vim takes a very long time to start up

setup clipboard First, try running Vim with the following command: $ vim -X You can try using the -X –startuptime <file> options together to see if the “setup clipboard” component is still slow. If -X helps, you can get the same effect by adding the following line to your vimrc file: set clipboard=exclude:.* Explanation If … Read more

How to get values from appsettings.json in a console application using .NET Core?

Your example is mixing in some ASP NET Core approaches that expect your code to be hosted. To minimally solve the issue of getting options or settings from a JSON configuration, consider the following: A config.json file, set to “Copy to Output Directory” so that it is included with the build: { “MyFirstClass”: { “Option1”: … Read more

How can I run a Perl script as a system daemon in linux?

The easiest way is to use Proc::Daemon. #!/usr/bin/perl use strict; use warnings; use Proc::Daemon; Proc::Daemon::Init; my $continue = 1; $SIG{TERM} = sub { $continue = 0 }; while ($continue) { #do stuff } Alternately you could do all of the things Proc::Daemon does: Fork a child and exits the parent process. Become a session leader … Read more