示例#1
0
        private void ConfigureServices(IServiceCollection serviceCollection)
        {
            string appDataPath = localAppDataExample.AssemblyFolderPath();

            // Add logging
            serviceCollection.AddSingleton(LoggerFactory.Create(builder =>
            {
                builder.AddSerilog(dispose: true);
            }));

            serviceCollection.AddLogging();

            // Build configuration
            // Directory.GetParent(AppContext.BaseDirectory).FullName -> path to \bin\Debug\netcoreapp3.1
            configuration = new ConfigurationBuilder()
                            .SetBasePath(appDataPath)
                            .AddJsonFile("appsettings.json", false)
                            .Build();

            // Add access to generic IConfigurationRoot
            serviceCollection.AddSingleton(configuration);

            // Add app
            serviceCollection.AddTransient <AppExample>();
        }
示例#2
0
        static async Task Main(string[] args)
        {
            FileStreamExample fileStreamExample = new FileStreamExample();
            await fileStreamExample.WriteFileAsync();

            await fileStreamExample.ReadFileAsync();

            fileStreamExample.WriteReadFileSeek();
            await fileStreamExample.ManualDisposingFileStreamAsync();

            StreamWriterReaderExample streamWriterReaderExample = new StreamWriterReaderExample();
            string testText = "hello world-Dima2020-23-03";
            await streamWriterReaderExample.WriteFileAsync(testText);

            await streamWriterReaderExample.ReadFileAsync();

            BinaryWriterReaderExample binaryWriterReaderExample = new BinaryWriterReaderExample();

            binaryWriterReaderExample.WriteFile();
            binaryWriterReaderExample.ReadFile();

            Console.WriteLine("\n\nEnvironment Variables Example:\n\n");

            EnvironmentVariablesExample environmentVariablesExample = new EnvironmentVariablesExample();

            environmentVariablesExample.DisplaySeveralEnvironmentVariables();

            Console.WriteLine("\n\nLocal App Data Example:\n\n");

            LocalAppDataExample localAppDataExample = new LocalAppDataExample();
            string assemblyFolderPath = localAppDataExample.AssemblyFolderPath();

            Console.WriteLine("Assembly folder path: " + assemblyFolderPath);
            string fileName = "appsettings.json";
            await localAppDataExample.GetFileAsync(fileName);

            Console.WriteLine("\n\nApp Settings Example:\n\n");

            AppSettingsExample appSettingsExample = new AppSettingsExample();
            await appSettingsExample.LogExample();

            Console.WriteLine("\n\nLogs from Mongo database:\n\n");
            MongoDbLogger mongoDbLogger = new MongoDbLogger();
            await mongoDbLogger.GetLogsFromMongoDb();
        }