Skip to content

Commit 28c2946

Browse files
committed
update readme
1 parent fa54973 commit 28c2946

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,89 @@ In your application's `App.config` or `Web.config` file, specify the file sink a
5454
### Async approach
5555
It is possible to configure the collector using [Serilog.Sinks.Async](https://github.com/serilog/serilog-sinks-async) to have an async approach.
5656

57+
### Example Configuration for ASP.NET
58+
59+
```c#
60+
public static class Program
61+
{
62+
private const string OutputTemplate = "{Timestamp:HH:mm:ss.fff} [{Level:u1}] {Message:lj}{NewLine}{Exception}";
63+
64+
public static async Task<int> Main(string[] args)
65+
{
66+
// azure home directory
67+
var homeDirectory = Environment.GetEnvironmentVariable("HOME") ?? ".";
68+
var logDirectory = Path.Combine(homeDirectory, "LogFiles");
69+
70+
Log.Logger = new LoggerConfiguration()
71+
.MinimumLevel.Verbose()
72+
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
73+
.Enrich.FromLogContext()
74+
.WriteTo.Console(outputTemplate: OutputTemplate)
75+
.WriteTo.File(
76+
path: $"{logDirectory}/boot.txt",
77+
rollingInterval: RollingInterval.Day,
78+
shared: true,
79+
flushToDiskInterval: TimeSpan.FromSeconds(1),
80+
outputTemplate: OutputTemplate,
81+
retainedFileCountLimit: 10
82+
)
83+
.CreateBootstrapLogger();
84+
85+
try
86+
{
87+
Log.Information("Starting web host");
88+
89+
var builder = Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder(args);
90+
91+
builder.Host
92+
.UseSerilog((context, services, configuration) => configuration
93+
.ReadFrom.Configuration(context.Configuration)
94+
.ReadFrom.Services(services)
95+
.Enrich.FromLogContext()
96+
.Enrich.WithProperty("ApplicationName", builder.Environment.ApplicationName)
97+
.Enrich.WithProperty("EnvironmentName", builder.Environment.EnvironmentName)
98+
.WriteTo.Console(outputTemplate: OutputTemplate)
99+
.WriteTo.File(
100+
path: $"{logDirectory}/log.txt",
101+
rollingInterval: RollingInterval.Day,
102+
shared: true,
103+
flushToDiskInterval: TimeSpan.FromSeconds(1),
104+
outputTemplate: OutputTemplate,
105+
retainedFileCountLimit: 10
106+
)
107+
.WriteTo.AzureTableStorage(
108+
connectionString: context.Configuration.GetConnectionString("StorageAccount"),
109+
propertyColumns: new[] { "SourceContext", "RequestId", "RequestPath", "ConnectionId", "ApplicationName", "EnvironmentName" }
110+
)
111+
);
112+
113+
ConfigureServices(builder);
114+
115+
var app = builder.Build();
116+
117+
ConfigureMiddleware(app);
118+
119+
await app.RunAsync();
120+
121+
return 0;
122+
}
123+
catch (Exception ex)
124+
{
125+
Log.Fatal(ex, "Host terminated unexpectedly");
126+
return 1;
127+
}
128+
finally
129+
{
130+
await Log.CloseAndFlushAsync();
131+
}
132+
}
133+
134+
private static void ConfigureServices(WebApplicationBuilder builder)
135+
{
136+
}
137+
138+
private static void ConfigureMiddleware(Microsoft.AspNetCore.Builder.WebApplication app)
139+
{
140+
}
141+
}
142+
```

src/Serilog.Sinks.AzureTableStorage/Sinks/AzureTableStorage/DefaultDocumentFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Serilog.Sinks.AzureTableStorage;
1414
/// </summary>
1515
public class DefaultDocumentFactory : IDocumentFactory
1616
{
17-
// Azure tables support a maximum of 255 columns.
18-
private const int _maxDocumentColumns = 255;
17+
// Azure tables support a maximum of 255 columns. Nine consumed by default
18+
private const int _maxDocumentColumns = 255 - 9;
1919

2020
private readonly AzureTableStorageSinkOptions _sinkOptions;
2121

0 commit comments

Comments
 (0)