私はコンソールアプリケーションをdot net core 1.1で使用しています。分。アプリケーションの内部には、設定ファイルが呼び出されます。私は以下のコードを添付しています。いつかのためのアプリケーションを実行した後dotnetコアのjsonファイルを読み込んでいるときにエラーが発生しました。「inotifyインスタンス数に設定されたユーザの制限(128)に達しました。」
public static T GetAppConfig<T>(string key, T defaultValue = default(T))
{
T value = default(T);
logger.Debug($"Reading App Config {key}");
try
{
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true)
.AddJsonFile($"appsettings.{environmentName}.json", true, true)
.AddEnvironmentVariables();
var configuration = builder.Build();
T setting = (T)Convert.ChangeType(configuration[key], typeof(T));
value = setting;
if (setting == null)
value = defaultValue;
}
catch (Exception ex)
{
logger.Warn(ex, $"An exception occured reading app key {key} default value {defaultValue} applied.");
value = defaultValue;
}
return value;
}
、このエラーは私のログファイルになっている「はinotifyインスタンスの数に設定されたユーザー制限(128)に達してきました」。完全なスタックトレースを見つけてください。
An exception occured reading app key DeviceId default value applied. System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached. at System.IO.FileSystemWatcher.StartRaisingEvents() at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed() at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter) at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer) at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder) at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at app.Shared.Utilities.GetAppConfig[T](String key, T defaultValue) in /var/app/source/app/app.Shared/Utilities.cs:line 33 at System.IO.FileSystemWatcher.StartRaisingEvents() at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed() at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter) at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer) at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder) at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at app.Shared.Utilities.GetAppConfig[T](String key, T defaultValue) in /var/app/source/app/app.Shared/Utilities.cs:line 33
このコードの問題点を教えてください。
ツェン経由でサービスに注入、返信いただきありがとうございます。変更フラグのリロードを変更します。それは問題を解決するのですか?私はこれをスケジューラの下で実行しているからです。したがって、シングルトンを使用している場合は、同じオブジェクトを使用するかどうかを次のスケジュールで実行します。コンテナはメインで再び初期化されるためです。 – Vipin
リロードフラグを削除するとそれを修正する必要がありますが、実行するたびにファイルを読み込む必要があります。シングルトンについて:スケジューラの仕組みによって異なります。スケジューラ実行ごとにスコープ付きコンテナを作成すると、シングルトンはすべてのインスタンスで同じになります。しかし、それはこの質問の範囲外です – Tseng
@Tsengなぜ設定のための静的フィールドを避けるのですか? –