Beispiel #1
0
        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
                         .MinimumLevel.Override("System", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         // uncomment to write to Azure diagnostics stream
                         .WriteTo.File(
                @".\identityserver.txt",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
                         .CreateLogger();

            try
            {
                Log.Information("Starting host...");
                CreateHostBuilder(args).Build().Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .Enrich.FromLogContext()
                         .Enrich.WithProperty("Application", "TodoApp.Api")
                         .Enrich.WithProperty("Version", typeof(Program).Assembly.GetName().Version !.ToString())
                         .WriteTo.Console(new JsonFormatter())
                         .CreateLogger();

            try
            {
                Log.Information("Starting up");
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception exc)
            {
                Log.Fatal(exc, "Error starting app: {ErrorMessage}", exc.Message);
                throw;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #3
0
        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .Enrich.FromLogContext()
                         .WriteTo.File(
                "applog.txt",
                outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.Console(
                outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}")
                         .CreateLogger();

            try
            {
                Log.Information("Getting the motors running...");

                CreateHostBuilder(args).Build().Run();

                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #4
0
        public static int Main(string[] args)
        {
            Console.Title = "IdentityServer Center";

            const string outputTemplate =
                "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}";

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
                         .MinimumLevel.Override("System", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         // uncomment to write to Azure diagnostics stream
                         .WriteTo.File(
                @"LogFiles\log.log",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                restrictedToMinimumLevel: LogEventLevel.Warning,
                rollingInterval: RollingInterval.Day,
                outputTemplate: outputTemplate,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.Console(outputTemplate: outputTemplate, theme: AnsiConsoleTheme.Code)
                         .CreateLogger();

            try
            {
                var seed = args.Contains("/seed");
                if (seed)
                {
                    args = args.Except(new[] { "/seed" }).ToArray();
                }

                var host = CreateHostBuilder(args).Build();

                if (seed)
                {
                    Log.Information("Seeding database...");
                    SeedData.EnsureSeedData(host.Services);
                    Log.Information("Done seeding database.");
                }

                Log.Information("Starting host...");
                host.Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                Log.Information("Host Closed.");
                Log.CloseAndFlush();
            }
        }
Beispiel #5
0
        public static int Main(string[] args)
        {
            AppVersionInfo.InitialiseBuildInfoGivenPath(AppDomain.CurrentDomain.BaseDirectory);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
                         .MinimumLevel.Override("System", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         // uncomment to write to Azure diagnostics stream
                         .WriteTo.File(
                @"D:\home\LogFiles\Application\identityserver.txt",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
                         .CreateLogger();

            try
            {
                var seed = args.Contains("/seed");
                if (seed)
                {
                    args = args.Except(new[] { "/seed" }).ToArray();
                }

                var host = CreateHostBuilder(args)
                           .Build();


                if (seed)
                {
                    Log.Information("Seeding database...");
                    var config           = host.Services.GetRequiredService <IConfiguration>();
                    var connectionString = config["SqlConnection"];
                    SeedData.EnsureSeedData(connectionString);
                    Log.Information("Done seeding database.");
                    return(0);
                }

                Log.Information("Starting host...");
                host.Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #6
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddInfrastructure();
     services.AddControllers();
     Log.Logger = new LoggerConfiguration()
                  .WriteTo.File("log.txt", fileSizeLimitBytes: 1_000_000, rollOnFileSizeLimit: true)
                  .WriteTo.Console()
                  .WriteTo.Seq("http://localhost:5341")
                  .CreateLogger();
     services.AddSingleton <Serilog.ILogger>(Log.Logger);
 }
Beispiel #7
0
        private static void InitLogger()
        {
            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .Destructure.ByTransforming <JsonWebToken>(jwt =>
            {
                var result = new Dictionary <string, object>();

                foreach (var claim in jwt.Claims)
                {
                    if (result.TryGetValue(claim.Type, out var value))
                    {
                        var list = value as List <string>;

                        if (list == null)
                        {
                            list = new List <string>();
                            list.Add((string)value);
                            result[claim.Type] = list;
                        }

                        list.Add(claim.Value);
                    }
                    else
                    {
                        var claimValue = claim.Value;

                        switch (claim.Type)
                        {
                        case "exp":
                        case "nbf":
                        case "iat":
                            if (long.TryParse(claimValue, out var timestamp))
                            {
                                var dt      = DateTimeOffset.FromUnixTimeSeconds(timestamp).ToLocalTime();
                                claimValue += $" (which is {dt})";
                            }

                            break;
                        }

                        result.Add(claim.Type, claimValue);
                    }
                }

                return(result);
            })
                         .WriteTo.Console()
                         .CreateLogger();
        }
        public static async Task Main(string[] args)
        {
            var path = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "LOG"), "ELA_AUTH_LOG.txt"); //ELA_AUTH_LOG.txt

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .WriteTo.File(
                path,
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.Console()
                         .CreateLogger();

            try
            {
                var host = CreateHostBuilder(args).Build();

                using (var serviceScope = host.Services.CreateScope())
                {
                    var dbContext = serviceScope.ServiceProvider.GetRequiredService <ElaAuthContext>();

                    await dbContext.Database.MigrateAsync();

                    var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                    var userManager = serviceScope.ServiceProvider.GetRequiredService <UserManager <AppUser> >();
                    var mySql       = serviceScope.ServiceProvider.GetRequiredService <MySqlDataContext>();

                    var baseIdentityInitializer = new InitializeIdentity(dbContext, userManager, roleManager, mySql);
                    await baseIdentityInitializer.Initialize();
                }

                await host.RunAsync();
            }
            catch (Exception e)
            {
                Log.Fatal(e, "Application start-up failed");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #9
0
        public static int Main(string[] args)
        {
            var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
                         .MinimumLevel.Override("System", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                         .MinimumLevel.Override("Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler", LogEventLevel.Warning)
                         .MinimumLevel.Override("Aio.Presentation.Web.HostedServices", LogEventLevel.Warning)
                         .Enrich.FromLogContext()
                         .WriteTo.File(
                "./logs/aio.txt",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1)
                )
                         .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
                         .CreateLogger();

            try
            {
                Log.Information("Starting host...");
                CreateHostBuilder(args).Build().Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #10
0
        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
                         .MinimumLevel.Override("System", LogEventLevel.Warning)
                         .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.File(
                @"C:\logs\framework.featurecenter.xenial.io\framework.featurecenter.xenial.io.log",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code)
                         .CreateLogger();

            try
            {
                Log.Information("Starting host...");
                if (ContainsArgument(args, "help") || ContainsArgument(args, "h"))
                {
                    Console.WriteLine("Updates the database when its version does not match the application's version.");
                    Console.WriteLine();
                    Console.WriteLine($"    {Assembly.GetExecutingAssembly().GetName().Name}.exe --updateDatabase [--forceUpdate --silent]");
                    Console.WriteLine();
                    Console.WriteLine("--forceUpdate - Marks that the database must be updated whether its version matches the application's version or not.");
                    Console.WriteLine("--silent - Marks that database update proceeds automatically and does not require any interaction with the user.");
                    Console.WriteLine();
                    Console.WriteLine($"Exit codes: 0 - {DBUpdater.StatusUpdateCompleted}");
                    Console.WriteLine($"            1 - {DBUpdater.StatusUpdateError}");
                    Console.WriteLine($"            2 - {DBUpdater.StatusUpdateNotNeeded}");
                }
                else
                {
                    FrameworkSettings.DefaultSettingsCompatibilityMode = FrameworkSettingsCompatibilityMode.Latest;
                    var host = CreateHostBuilder(args).Build();
                    if (ContainsArgument(args, "updateDatabase"))
                    {
                        using var serviceScope = host.Services.CreateScope();
                        return(serviceScope.ServiceProvider.GetRequiredService <IDBUpdater>().Update(ContainsArgument(args, "forceUpdate"), ContainsArgument(args, "silent")));
                    }
                    else
                    {
                        Log.Information("Host run...");
                        host.Run();
                    }
                }
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Beispiel #11
0
        public async static Task Main(string[] args)
        {
            AppVersionInfo.InitialiseBuildInfoGivenPath(AppDomain.CurrentDomain.BaseDirectory);
            var buildInfo = AppVersionInfo.GetBuildInfo();

            var baseLoggerConfig = new LoggerConfiguration()
                                   .MinimumLevel.Debug()
                                   .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                                   .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
                                   .MinimumLevel.Override("System", LogEventLevel.Warning)
                                   .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)

                                   .Enrich.FromLogContext()
                                   .Enrich.WithProperty("ApplicationName", APP_NAME)
                                   .Enrich.WithProperty(nameof(buildInfo.BuildId), buildInfo.BuildId)
                                   .Enrich.WithProperty(nameof(buildInfo.BuildNumber), buildInfo.BuildNumber)
                                   .Enrich.WithProperty(nameof(buildInfo.BranchName), buildInfo.BranchName)
                                   .Enrich.WithProperty(nameof(buildInfo.CommitHash), buildInfo.CommitHash)
                                   .WriteTo.File(
                @"D:\home\LogFiles\Application\webapi.txt",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                                   .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code);



            try
            {
                var host = CreateHostBuilder(args).Build();
                using (var scope = host.Services.CreateScope())
                {
                    var services      = scope.ServiceProvider;
                    var env           = services.GetService <IWebHostEnvironment>();
                    var configuration = services.GetService <IConfiguration>();
                    if (env.IsProduction() && !string.IsNullOrWhiteSpace(configuration.GetValue <string>("APPINSIGHTS_INSTRUMENTATIONKEY")))
                    {
                        var telemetry = services.GetRequiredService <TelemetryConfiguration>();
                        baseLoggerConfig = baseLoggerConfig.WriteTo.ApplicationInsights(telemetry, TelemetryConverter.Traces);
                    }

                    Log.Logger = baseLoggerConfig.CreateLogger();

                    var logger = services.GetRequiredService <ILogger <Program> >();

                    logger.LogInformation($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}");
                    try
                    {
                        var context = services.GetRequiredService <ApplicationDbContext>();

                        if (context.Database.IsSqlServer())
                        {
                            logger.LogInformation("DataBase migration..");
                            await context.Database.MigrateAsync();

                            logger.LogInformation("DataBase migrated");
                        }

                        logger.LogInformation("DataBase seeding..");
                        await ApplicationDbContextSeed.SeedSampleDataAsync(context);
                    }
                    catch (Exception ex)
                    {
                        logger.LogError(ex, "An error occurred while migrating or seeding the database.");

                        throw;
                    }
                }
                Log.Information("Starting up..");
                await host.RunAsync();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Application start-up failed");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
 public ShopLogConfiguration(LogEventLevel level = LogEventLevel.Verbose)
 {
     WriteTo.Console(level, DefaultTemplate);
     WriteTo.RollingFile(".\\Logs\\shop_node_log_{HalfHour}.txt", level, DefaultTemplate);
 }