public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         // Add this line:
                         .WriteTo.File(
                @"log\myappMain.log",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                rollingInterval: RollingInterval.Day,
                outputTemplate: outputTemplate,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .WriteTo.File(
                @"log\myappMain.error.log",
                LogEventLevel.Error,
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                outputTemplate: outputTemplate,
                rollingInterval: RollingInterval.Day,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                         .CreateLogger();

            try
            {
                Log.Information("Starting web host");
                Log.Error("Starting web host test error");
                CreateHostBuilder(args).Build().Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
        public static async Task <IHostBuilder> RunWithSerilogAsync(this IHostBuilder hostBuilder)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
                         .Enrich.FromLogContext()
                         .WriteTo.Debug()
                         .WriteTo.Console(new RenderedCompactJsonFormatter() 0)
                         //.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}")
                         .WriteTo.File(new RenderedCompactJsonFormatter(), "/logs/log.ndjson")
                         .WriteTo.Seq(Environment.GetEnvironmentVariable("SEQ_URL") ?? "http://localhost:5341")
                         .CreateLogger()
            ;

            try
            {
                Log.Information("Starting up");

                hostBuilder.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
                                       .ReadFrom.Configuration(hostingContext.Configuration)
                                       .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
                                       .Enrich.FromLogContext()
                                       .WriteTo.Debug()
                                       .WriteTo.Console(new RenderedCompactJsonFormatter() 0)
                                       //.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}")
                                       .WriteTo.File(new RenderedCompactJsonFormatter(), "/logs/log.ndjson")
                                       .WriteTo.Seq(Environment.GetEnvironmentVariable("SEQ_URL") ?? "http://localhost:5341")
                                       );

                await hostBuilder.Build().RunAsync();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly");
                Log.Fatal(ex, "Application start-up failed");
            }
            finally
            {
                Log.CloseAndFlush();
            }

            return(hostBuilder);
        }
Пример #3
0
        public DefaultLoggerConfiguration(LogEventLevel level = LogEventLevel.Verbose, string fileName = null)
        {
            Enrich.FromLogContext();
            if (fileName != null)
            {
                WriteTo.File(fileName, level, DefaultTemplate);
            }
            else
            {
                WriteTo.RollingFile(".\\Logs\\log_{HalfHour}.txt", level, DefaultTemplate);
            }

            MinimumLevel.Is(level);
            Destructure.ByTransforming <Money>(r => new { r.Amount, r.CurrencyCode });
            Destructure.ByTransforming <Exception>(r => new { Type = r.GetType(), r.Message, r.StackTrace });
            Destructure.ByTransforming <MessageMetadata>(r => new { r.CasuationId, r.CorrelationId });
            Destructure.ByTransforming <PersistEventPack>(r => new { Size = r.Events?.Length });
            Destructure.ByTransforming <MessageMetadataEnvelop <ICommand> >(r => new { CommandType = r.Message.GetType(), CommandId = r.Message.Id, r.Metadata });
            Destructure.ByTransforming <MessageMetadataEnvelop <DomainEvent> >(r => new { EventType = r.Message.GetType(), EventId = r.Message.Id, r.Metadata });
            Destructure.ByTransforming <AggregateCommandExecutionContext>(r => new { CommandId = r.Command?.Id, Metadata = r.CommandMetadata });
            Destructure.ByTransforming <ProcessesTransitComplete>(r => new { Event = r.InitialMessage, ProducedCommandsNum = r.ProducedCommands.Length });
            Destructure.ByTransforming <CreateNewProcess>(r => new { Event = (r.Message?.Message as IHaveId)?.Id ?? r.Message?.Message, r.EnforcedId, r.Message?.Metadata });
        }
Пример #4
0
        static void Main(string[] args)
        {
            const string template = "{Timestamp:yy-MM-dd HH:mm:ss} [{Level}] {Indent:l}{Message}{NewLine}{Exception}";

            ParseOptions(args);
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Verbose()
                         .WriteTo.Console()
                         .WriteTo.Logger(
                x => x.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Fatal)
                .WriteTo.File($"logs/driver-fatal.log",
                              rollingInterval: RollingInterval.Day,
                              rollOnFileSizeLimit: true,
                              outputTemplate: template)
                )
                         .WriteTo.Logger(
                x => x.Filter.ByIncludingOnly(e => e.Level is LogEventLevel.Warning
                                              or LogEventLevel.Error)
                .WriteTo.File($"logs/driver-errors.log",
                              rollingInterval: RollingInterval.Day,
                              rollOnFileSizeLimit: true,
                              outputTemplate: template)
                )
                         .WriteTo.Logger(
                x => x.Filter.ByExcluding(e => e.Level is LogEventLevel.Warning
                                          or LogEventLevel.Error or LogEventLevel.Fatal or LogEventLevel.Verbose)
                .WriteTo.File($"logs/mud-info.log",
                              rollingInterval: RollingInterval.Day,
                              rollOnFileSizeLimit: true,
                              outputTemplate: template)
                ).CreateLogger();

            // Removed capturing of Ctrl-C since it failed across platforms
            // evaluate adding back later.
            Log.Information(AnsiColor.ReplaceColors("{GBringing the hyper-drive systems online...{n"));
            Core.StartKernel(Uid.Kernel);
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Serilog.Log.Logger = new LoggerConfiguration()
                                 .MinimumLevel.Debug()
                                 .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                                 .MinimumLevel.Override("System", LogEventLevel.Information)
                                 .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                                 //amit ebben a könyvtárban írok, az megjelenik az
                                 //azure AppService napló streamjében
                                 //ez már nem működik, helyette: https://github.com/serilog/serilog-aspnetcore
                                 //.WriteTo.File(@"D:\home\LogFiles\http\RawLogs\log.txt")
                                 .WriteTo.File(
                @"D:\home\LogFiles\Application\myapp.txt",
                fileSizeLimitBytes: 1_000_000,
                rollOnFileSizeLimit: true,
                shared: true,
                flushToDiskInterval: TimeSpan.FromSeconds(1))
                                 .WriteTo.File(@"log.txt")
                                 .CreateLogger();

            var msAppIdKey = Configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
            var msAppPwd   = Configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppPasswordKey)?.Value;

            var credentialProvider = new StaticCredentialProvider(
                msAppIdKey,
                msAppPwd
                );

            var store = new InMemoryDataStore();

            Conversation.UpdateContainer(builder =>
            {
                builder.Register(c => store)
                .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore)
                .AsSelf()
                .SingleInstance();

                builder.Register(c => new CachingBotDataStore(store,
                                                              CachingBotDataStoreConsistencyPolicy
                                                              .ETagBasedConsistency))
                .As <IBotDataStore <BotData> >()
                .AsSelf()
                .InstancePerLifetimeScope();

                builder.Register(c =>
                                 new MicrosoftAppCredentials(msAppIdKey, msAppPwd))
                .SingleInstance();
            });

            services.AddAuthentication(
                o =>
            {
                o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                o.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }
                ).AddBotAuthentication(credentialProvider);

            services.AddSingleton(typeof(ICredentialProvider), credentialProvider);

            services.AddMvc(
                o =>
            {
                o.Filters.Add(typeof(TrustServiceUrlAttribute));
            }
                ).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }