Skip to content

Commit a371ce6

Browse files
authored
Fix schedule sample logging setup (#392)
* fix logging in schedule sample * logging in consoleapp
1 parent bbceabc commit a371ce6

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

samples/ScheduleConsoleApp/Program.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,9 @@
3636
builder.UseScheduledTasks();
3737
});
3838

39-
// Configure console logging
40-
builder.Services.AddLogging(logging =>
41-
{
42-
logging.AddSimpleConsole(options =>
43-
{
44-
options.SingleLine = true;
45-
options.UseUtcTimestamp = true;
46-
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
47-
});
48-
});
39+
// Configure logging
40+
builder.Services.AddSingleton<ILogger>(sp => sp.GetRequiredService<ILoggerFactory>().CreateLogger<Program>());
41+
builder.Services.AddLogging();
4942

5043
IHost host = builder.Build();
5144
await host.StartAsync();

samples/ScheduleWebApp/Program.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
string connectionString = builder.Configuration.GetValue<string>("DURABLE_TASK_SCHEDULER_CONNECTION_STRING")
1515
?? throw new InvalidOperationException("Missing required configuration 'DURABLE_TASK_SCHEDULER_CONNECTION_STRING'");
1616

17+
builder.Services.AddSingleton<ILogger>(sp => sp.GetRequiredService<ILoggerFactory>().CreateLogger<Program>());
18+
builder.Services.AddLogging();
1719
// Add all the generated orchestrations and activities automatically
1820
builder.Services.AddDurableTaskWorker(builder =>
1921
{
@@ -33,17 +35,6 @@
3335
builder.UseScheduledTasks();
3436
});
3537

36-
// Configure console logging using the simpler, more compact format
37-
builder.Services.AddLogging(logging =>
38-
{
39-
logging.AddSimpleConsole(options =>
40-
{
41-
options.SingleLine = true;
42-
options.UseUtcTimestamp = true;
43-
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
44-
});
45-
});
46-
4738
// Configure the HTTP request pipeline
4839
builder.Services.AddControllers().AddJsonOptions(options =>
4940
{

0 commit comments

Comments
 (0)