-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.Infrastructure.cs
More file actions
242 lines (209 loc) · 9.81 KB
/
Log.Infrastructure.cs
File metadata and controls
242 lines (209 loc) · 9.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using Microsoft.Extensions.Logging;
namespace BookStore.ApiService.Infrastructure.Logging;
/// <summary>
/// Infrastructure-related log messages for middleware, startup, and system operations.
/// </summary>
public static partial class Log
{
public static partial class Infrastructure
{
[LoggerMessage(
Level = LogLevel.Information,
Message = "Marten metadata set for {Method} {Path}: CorrelationId={CorrelationId}, CausationId={CausationId}, UserId={UserId}, RemoteIp={RemoteIp}")]
public static partial void MartenMetadataApplied(
ILogger logger,
string method,
string path,
string correlationId,
string causationId,
string? userId,
string? remoteIp);
// Logging Enricher Middleware
[LoggerMessage(
Level = LogLevel.Debug,
Message = "Request started: {Method} {Path} from {RemoteIp}")]
public static partial void RequestStarted(
ILogger logger,
string method,
string path,
string remoteIp);
// Database Seeding
[LoggerMessage(
Level = LogLevel.Information,
Message = "Starting database seeding")]
public static partial void DatabaseSeedingStarted(ILogger logger);
[LoggerMessage(
Level = LogLevel.Information,
Message = "Database seeding completed successfully")]
public static partial void DatabaseSeedingCompleted(ILogger logger);
[LoggerMessage(
Level = LogLevel.Critical,
Message = "Database seeding failed")]
public static partial void DatabaseSeedingFailed(ILogger logger, Exception exception);
// Projection Initialization
[LoggerMessage(
Level = LogLevel.Information,
Message = "Waiting for async projections to complete...")]
public static partial void WaitingForProjections(ILogger logger);
[LoggerMessage(
Level = LogLevel.Information,
Message = "All projections are ready: {BookCount} books, {AuthorCount} authors, {CategoryCount} categories, {PublisherCount} publishers")]
public static partial void ProjectionsReady(
ILogger logger,
int bookCount,
int authorCount,
int categoryCount,
int publisherCount);
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Projection initialization timed out after {TimeoutSeconds}s. Some projections may not be ready.")]
public static partial void ProjectionTimeout(ILogger logger, double timeoutSeconds);
[LoggerMessage(
Level = LogLevel.Debug,
Message = "Checking projection status: Books={BookCount}, Authors={AuthorCount}, Categories={CategoryCount}, Publishers={PublisherCount}")]
public static partial void ProjectionStatus(
ILogger logger,
int bookCount,
int authorCount,
int categoryCount,
int publisherCount);
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Cache invalidation not implemented for projection type {ProjectionType}. Consider adding a case to handle this projection.")]
public static partial void CacheInvalidationNotImplemented(ILogger logger, string projectionType);
// Projection Commit Listener
[LoggerMessage(
Level = LogLevel.Debug,
Message = "AfterCommitAsync called. Inserted: {InsertedCount}, Updated: {UpdatedCount}, Deleted: {DeletedCount}")]
public static partial void AfterCommitAsync(
ILogger logger,
int insertedCount,
int updatedCount,
int deletedCount);
[LoggerMessage(
Level = LogLevel.Error,
Message = "Error processing projection commit")]
public static partial void ErrorProcessingProjectionCommit(ILogger logger, Exception exception);
[LoggerMessage(
Level = LogLevel.Debug,
Message = "Processing {ChangeType}: {DocumentType}")]
public static partial void ProcessingDocumentChange(
ILogger logger,
string changeType,
string documentType);
[LoggerMessage(
Level = LogLevel.Error,
Message = "Error processing {ChangeType} document of type {DocumentType}")]
public static partial void ErrorProcessingDocumentChange(
ILogger logger,
Exception exception,
string changeType,
string documentType);
[LoggerMessage(
Level = LogLevel.Debug,
Message = "Invalidated cache {ItemTag} and {ListTag}")]
public static partial void CacheInvalidated(
ILogger logger,
string itemTag,
string listTag);
[LoggerMessage(
Level = LogLevel.Information,
Message = "Sending {NotificationType} for {EntityType}")]
public static partial void SendingNotification(
ILogger logger,
string notificationType,
string entityType);
// Startup
[LoggerMessage(
Level = LogLevel.Information,
Message = "Starting the API Service...")]
public static partial void StartingApiService(ILogger logger);
[LoggerMessage(
Level = LogLevel.Information,
Message = "Registering Marten events for the first time...")]
public static partial void RegisteringMartenEvents(ILogger logger);
[LoggerMessage(
Level = LogLevel.Critical,
Message = "Failed to register Marten events")]
public static partial void FailedToRegisterMartenEvents(ILogger logger, Exception exception);
[LoggerMessage(
Level = LogLevel.Error,
Message = "An error occurred during startup")]
public static partial void StartupError(ILogger logger, Exception exception);
[LoggerMessage(
Level = LogLevel.Warning,
Message = "JWT algorithm HS256 is configured in non-development environment {EnvironmentName}. HS256 remains supported, but RS256 with asymmetric keys is recommended for production deployments.")]
public static partial void JwtHs256ConfiguredInProduction(ILogger logger, string environmentName);
[LoggerMessage(
Level = LogLevel.Error,
Message = "Unhandled exception: {Message}")]
public static partial void UnhandledException(ILogger logger, Exception exception, string message);
[LoggerMessage(
Level = LogLevel.Information,
Message = "[WOLVERINE-CORRELATION] Session CorrelationId: {SessionId}, CausationId: {SessionCid} (HttpContext present: {HasContext})")]
public static partial void WolverineCorrelation(
ILogger logger,
string? sessionId,
string? sessionCid,
bool hasContext);
[LoggerMessage(
Level = LogLevel.Information,
Message = "Background startup task running. Environment: {Environment}, SeedingEnabled: {SeedingEnabled}")]
public static partial void StartupTaskRunning(
ILogger logger,
string environment,
bool seedingEnabled);
[LoggerMessage(
Level = LogLevel.Information,
Message = "Seeding tenant: {TenantId}")]
public static partial void SeedingTenant(
ILogger logger,
string tenantId);
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Database seeding failed (attempt {RetryCount}/{MaxRetries}). Retrying in {RetryDelay}s...")]
public static partial void SeedingFailedRetrying(
ILogger logger,
Exception exception,
int retryCount,
int maxRetries,
double retryDelay);
[LoggerMessage(
Level = LogLevel.Error,
Message = "Database seeding failed after {RetryCount} attempts. Application may not behave correctly.")]
public static partial void SeedingFailedMaxRetries(
ILogger logger,
Exception exception,
int retryCount);
[LoggerMessage(
Level = LogLevel.Information,
Message = "[DEBUG_LISTENER] HandleUserChangeAsync for {UserId}. Favorites: {Count}")]
public static partial void DebugHandleUserChange(
ILogger logger,
Guid userId,
int count);
[LoggerMessage(
Level = LogLevel.Critical,
Message = "Rate limiting is disabled (RateLimit:Disabled=true) in non-development environment '{EnvironmentName}'. This exposes the API to abuse and must not be used in production.")]
public static partial void RateLimitingDisabledInProduction(ILogger logger, string environmentName);
[LoggerMessage(
Level = LogLevel.Error,
Message = "Unexpected exception during token validation. The request will be rejected.")]
public static partial void TokenValidationUnexpectedError(ILogger logger, Exception exception);
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Invalid Jwt:ExpirationMinutes value '{ConfiguredMinutes}'. Falling back to default {DefaultExpirationMinutes} minutes.")]
public static partial void InvalidJwtExpirationMinutes(
ILogger logger,
string configuredMinutes,
int defaultExpirationMinutes);
[LoggerMessage(
Level = LogLevel.Information,
Message = "Creating {NotificationType} for book {BookId}, version {Version}")]
public static partial void CreatingBookNotification(
ILogger logger,
string notificationType,
Guid bookId,
long version);
}
}