|
27 | 27 | using System.Web.Http; |
28 | 28 | using System.Web.Optimization; |
29 | 29 | using System.Web.Routing; |
30 | | - |
| 30 | +using Microsoft.Extensions.Logging; |
31 | 31 | using Rock; |
32 | 32 | using Rock.Blocks; |
33 | 33 | using Rock.Communication; |
34 | 34 | using Rock.Configuration; |
35 | 35 | using Rock.Data; |
36 | 36 | using Rock.Enums.Cms; |
| 37 | +using Rock.Logging; |
37 | 38 | using Rock.Model; |
38 | 39 | using Rock.Observability; |
39 | 40 | using Rock.Security; |
|
43 | 44 | using Rock.Web.UI; |
44 | 45 | using Rock.WebStartup; |
45 | 46 |
|
| 47 | +[assembly: Rock.Logging.RockLoggingCategory( "RockWeb.Global" )] |
46 | 48 | namespace RockWeb |
47 | 49 | { |
48 | 50 | /// <summary> |
@@ -235,7 +237,7 @@ private void ApplicationStartupStage2() |
235 | 237 |
|
236 | 238 | SetError66(); |
237 | 239 | var startupException = new RockStartupException( "Error occurred during application startup", ex ); |
238 | | - LogError( startupException, null ); |
| 240 | + LogException( startupException, null ); |
239 | 241 | throw startupException; |
240 | 242 | } |
241 | 243 |
|
@@ -358,7 +360,7 @@ private static void StartEnsureChromeEngineThread() |
358 | 360 | } |
359 | 361 | catch ( Exception ex ) |
360 | 362 | { |
361 | | - LogError( ex, null ); |
| 363 | + LogException( ex, null ); |
362 | 364 | } |
363 | 365 | } ).Start(); |
364 | 366 | } |
@@ -1194,17 +1196,42 @@ public static void DrainTransactionQueue() |
1194 | 1196 | if ( !Global.QueueInUse ) |
1195 | 1197 | { |
1196 | 1198 | Global.QueueInUse = true; |
1197 | | - RockQueue.Drain( ( ex ) => LogError( ex, null ) ); |
| 1199 | + RockQueue.Drain( ( ex ) => WriteErrorToRockLog( ex, "Rock.Transactions", null ) ); |
1198 | 1200 | Global.QueueInUse = false; |
1199 | 1201 | } |
1200 | 1202 | } |
1201 | 1203 |
|
| 1204 | + /// <summary> |
| 1205 | + /// A handler for Rock Logging exception messages via Rock Logger. |
| 1206 | + /// If a message is provided, it will log that message otherwise |
| 1207 | + /// it will log the exception message. |
| 1208 | + /// </summary> |
| 1209 | + /// <param name="ex"></param> |
| 1210 | + private static void WriteErrorToRockLog( Exception ex, string loggerCategory, string message ) |
| 1211 | + { |
| 1212 | + if ( string.IsNullOrWhiteSpace( loggerCategory ) ) |
| 1213 | + { |
| 1214 | + loggerCategory = "RockWeb.Global"; |
| 1215 | + } |
| 1216 | + |
| 1217 | + var logger = RockLogger.LoggerFactory.CreateLogger( loggerCategory ); |
| 1218 | + |
| 1219 | + if ( !string.IsNullOrWhiteSpace( message ) ) |
| 1220 | + { |
| 1221 | + logger.LogError( ex, message ); |
| 1222 | + } |
| 1223 | + else |
| 1224 | + { |
| 1225 | + logger.LogError( ex.Message ); |
| 1226 | + } |
| 1227 | + } |
| 1228 | + |
1202 | 1229 | /// <summary> |
1203 | 1230 | /// Logs the error to database |
1204 | 1231 | /// </summary> |
1205 | 1232 | /// <param name="ex">The ex.</param> |
1206 | 1233 | /// <param name="context">The context.</param> |
1207 | | - private static void LogError( Exception ex, HttpContext context ) |
| 1234 | + private static void LogException( Exception ex, HttpContext context ) |
1208 | 1235 | { |
1209 | 1236 | int? pageId; |
1210 | 1237 | int? siteId; |
@@ -1278,7 +1305,7 @@ public static void CacheItemRemoved( string k, object v, CacheItemRemovedReason |
1278 | 1305 | } |
1279 | 1306 | catch ( Exception ex ) |
1280 | 1307 | { |
1281 | | - LogError( ex, null ); |
| 1308 | + LogException( ex, null ); |
1282 | 1309 | } |
1283 | 1310 | } |
1284 | 1311 |
|
@@ -1308,7 +1335,7 @@ Rock.SystemKey.SystemSetting.ENABLE_KEEP_ALIVE can be enabled in Rock's System S |
1308 | 1335 | } |
1309 | 1336 | catch ( Exception ex ) |
1310 | 1337 | { |
1311 | | - LogError( new Exception( "Error doing KeepAlive request.", ex ), null ); |
| 1338 | + LogException( new Exception( "Error doing KeepAlive request.", ex ), null ); |
1312 | 1339 | } |
1313 | 1340 | } |
1314 | 1341 | } |
|
0 commit comments