| | 1 | | Imports Microsoft.Win32 |
| | 2 | | Imports System.Reflection |
| | 3 | | Imports System.Runtime.CompilerServices |
| | 4 | |
|
| | 5 | | #If NETFRAMEWORK Then |
| | 6 | | Imports System.Configuration |
| | 7 | | #Else |
| | 8 | | Imports Microsoft.Extensions.Configuration |
| | 9 | | #End If |
| | 10 | |
|
| | 11 | | ''' <summary> |
| | 12 | | ''' Provides high-level utilities for logging to the Windows Event Log in a simplified and customizable way. |
| | 13 | | ''' </summary><remarks> |
| | 14 | | ''' <para> |
| | 15 | | ''' This module abstracts common patterns for writing entries to the Windows Event Log. It simplifies usage by handling: |
| | 16 | | ''' </para> |
| | 17 | | ''' <list type="bullet"> |
| | 18 | | ''' <item>Automatic validation and creation of logs and sources.</item> |
| | 19 | | ''' <item>Falls back when <c>log</c> or <c>source</c> parameters are not provided.</item> |
| | 20 | | ''' <item>Automatic source naming based on the calling method and class context.</item> |
| | 21 | | ''' <item>Safe handling and truncation of long messages to comply with system limits.</item> |
| | 22 | | ''' </list> |
| | 23 | | ''' <para> |
| | 24 | | ''' The default event log is <c>Application</c>. If no source is provided, a fully qualified method name |
| | 25 | | ''' (including namespace and class) is used as the source identifier. |
| | 26 | | ''' </para> |
| | 27 | | ''' <para> |
| | 28 | | ''' This module is suitable for both production use (via <see cref="RealEventLogWriter" />) and unit testing |
| | 29 | | ''' (via a test implementation such as <c>EventLogHelper.Tests.TestEventLogWriter</c> in a separate test project). |
| | 30 | | ''' </para> |
| | 31 | | ''' </remarks> |
| | 32 | | Public Module SmartEventLogger |
| | 33 | |
|
| | 34 | | #Region " Process Support Objects ^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 35 | |
|
| | 36 | | ''' <summary> |
| | 37 | | ''' The current event log writer instance used by the logger. |
| | 38 | | ''' </summary> |
| | 39 | | ''' <remarks> |
| | 40 | | ''' By default, this is initialized to an instance of <see cref="RealEventLogWriter"/>, which writes to the actual |
| | 41 | | ''' Windows Event Log. This field is typically replaced during testing with a mock or stub implementation via the |
| | 42 | | ''' <see cref="SetWriter"/> method. |
| | 43 | | ''' </remarks> |
| 8 | 44 | | Private _writer As IEventLogWriter = New RealEventLogWriter() |
| | 45 | | ''' <summary> |
| | 46 | | ''' The registry reader |
| | 47 | | ''' </summary> |
| 8 | 48 | | Private _registryReader As IRegistryReader = New RealRegistryReader() |
| | 49 | |
|
| | 50 | | ''' <summary> |
| | 51 | | ''' Sets the <see cref="IEventLogWriter"/> implementation used for logging operations. |
| | 52 | | ''' </summary> |
| | 53 | | ''' <param name="writer"> |
| | 54 | | ''' The custom writer instance to use. This allows swapping out the default <see cref="RealEventLogWriter"/> |
| | 55 | | ''' for testing or alternate logging implementations. |
| | 56 | | ''' </param> |
| | 57 | | ''' <remarks> |
| | 58 | | ''' This method is primarily intended for use in unit tests or advanced scenarios where log output should be redirec |
| | 59 | | ''' or suppressed. For example, a test implementation may capture and inspect log data without writing to the real e |
| | 60 | | ''' </remarks> |
| 132 | 61 | | Public Sub SetWriter(writer As IEventLogWriter) |
| | 62 | |
|
| 264 | 63 | | _writer = writer |
| | 64 | |
|
| 264 | 65 | | End Sub |
| | 66 | |
|
| | 67 | | ''' <summary> |
| | 68 | | ''' Specifies the <see cref="IRegistryReader"/> implementation to use when accessing |
| | 69 | | ''' the Windows Registry for log-related operations (e.g., determining default event log sources). |
| | 70 | | ''' </summary> |
| | 71 | | ''' <param name="reader"> |
| | 72 | | ''' The custom <see cref="IRegistryReader"/> instance to use. This is typically used for unit testing |
| | 73 | | ''' or customizing how registry access is performed. If not set, the default implementation will be used. |
| | 74 | | ''' </param> |
| | 75 | | ''' <remarks> |
| | 76 | | ''' This method allows injection of a mock or testable registry reader. In production, |
| | 77 | | ''' a default <c>RealRegistryReader</c> is used, but in unit tests, you may inject a fake |
| | 78 | | ''' reader to simulate different registry states without accessing the actual system registry. |
| | 79 | | ''' </remarks> |
| 24 | 80 | | Public Sub SetRegistryReader(reader As IRegistryReader) |
| | 81 | |
|
| 48 | 82 | | _registryReader = reader |
| | 83 | |
|
| 48 | 84 | | End Sub |
| | 85 | |
|
| | 86 | | #End Region |
| | 87 | |
|
| | 88 | | #Region " Initialization ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 89 | |
|
| | 90 | | ''' <summary> |
| | 91 | | ''' Has the Initialization process happened? |
| | 92 | | ''' This is used to prevent multiple initializations. |
| | 93 | | ''' </summary> |
| 8 | 94 | | Private _isInitialized As Boolean = False |
| | 95 | |
|
| | 96 | | ''' <summary> |
| | 97 | | ''' is initializing |
| | 98 | | ''' </summary> |
| 8 | 99 | | Private _isInitializing As Boolean = False |
| | 100 | |
|
| | 101 | | ''' <summary> |
| | 102 | | ''' The initialization lock |
| | 103 | | ''' </summary> |
| 8 | 104 | | Private ReadOnly _initLock As New Object() |
| | 105 | |
|
| | 106 | | ''' <summary> |
| | 107 | | ''' Initializes this instance. |
| | 108 | | ''' </summary> |
| 1968 | 109 | | Private Sub Initialize() |
| | 110 | |
|
| 5892 | 111 | | If _isInitialized OrElse _isInitializing Then Return |
| 24 | 112 | | _isInitializing = True |
| 36 | 113 | | SyncLock _initLock |
| 12 | 114 | | Try |
| 24 | 115 | | If Not _isInitialized Then |
| 24 | 116 | | MachineName = GetAppSetting("EventLogHelper.MachineName", MachineName) |
| 24 | 117 | | LogName = GetAppSetting("EventLogHelper.LogName", LogName) |
| 24 | 118 | | SourceName = GetAppSetting("EventLogHelper.SourceName", SourceName) |
| 24 | 119 | | MaxKilobytes = GetAppSetting("EventLogHelper.MaxKilobytes", MaxKilobytes) |
| 24 | 120 | | RetentionDays = GetAppSetting("EventLogHelper.RetentionDays", RetentionDays) |
| 24 | 121 | | WriteInitEntry = GetAppSetting("EventLogHelper.WriteInitEntry", WriteInitEntry) |
| 24 | 122 | | TruncationMarker = GetAppSetting("EventLogHelper.TruncationMarker", TruncationMarker) |
| 24 | 123 | | ContinuationMarker = GetAppSetting("EventLogHelper.ContinuationMarker", ContinuationMarker) |
| 24 | 124 | | AllowMultiEntryMessages = GetAppSetting("EventLogHelper.AllowMultiEntryMessages", AllowMultiEntryMes |
| | 125 | |
|
| 24 | 126 | | _isInitialized = True |
| 36 | 127 | | End If |
| 12 | 128 | | Finally |
| 24 | 129 | | _isInitializing = False |
| 12 | 130 | | End Try |
| 36 | 131 | | End SyncLock |
| | 132 | |
|
| 3936 | 133 | | End Sub |
| | 134 | |
|
| | 135 | | ''' <remarks> |
| | 136 | | ''' <para> |
| | 137 | | ''' This method reads predefined settings from the application's configuration and |
| | 138 | | ''' applies them to the corresponding <see cref="SmartEventLogger"/> properties. |
| | 139 | | ''' If a configuration value is not found, the property's existing value is retained. |
| | 140 | | ''' </para> |
| | 141 | | ''' <para> |
| | 142 | | ''' Calling this method explicitly is optional. Configuration will also be loaded |
| | 143 | | ''' automatically the first time a public method or property is accessed, unless it |
| | 144 | | ''' has already been initialized. |
| | 145 | | ''' </para> |
| | 146 | | ''' <para> |
| | 147 | | ''' Thread-safe: Initialization is guaranteed to run only once, even if called |
| | 148 | | ''' concurrently from multiple threads. |
| | 149 | | ''' </para> |
| | 150 | | ''' |
| | 151 | | ''' <para> |
| | 152 | | ''' Recognized configuration keys: |
| | 153 | | ''' </para> |
| | 154 | | ''' <list type="table"> |
| | 155 | | ''' <listheader> |
| | 156 | | ''' <term>Key</term> |
| | 157 | | ''' <description>Description</description> |
| | 158 | | ''' </listheader> |
| | 159 | | ''' |
| | 160 | | ''' <item> |
| | 161 | | ''' <term>EventLogHelper.MachineName</term> |
| | 162 | | ''' <description> |
| | 163 | | ''' The name of the machine where the event log resides. Use <c>"."</c> for the local machine. |
| | 164 | | ''' Defaults to the current value of <see cref="MachineName"/> (normally "."). |
| | 165 | | ''' </description> |
| | 166 | | ''' </item> |
| | 167 | | ''' |
| | 168 | | ''' <item> |
| | 169 | | ''' <term>EventLogHelper.LogName</term> |
| | 170 | | ''' <description> |
| | 171 | | ''' The name of the event log to write to (e.g., <c>"Application"</c>, <c>"System"</c>, or a custom log). |
| | 172 | | ''' Defaults to the current value of <see cref="LogName"/> (normally "Application"). |
| | 173 | | ''' </description> |
| | 174 | | ''' </item> |
| | 175 | | ''' |
| | 176 | | ''' <item> |
| | 177 | | ''' <term>EventLogHelper.SourceName</term> |
| | 178 | | ''' <description> |
| | 179 | | ''' The event source name associated with log entries. If not provided, a name is automatically |
| | 180 | | ''' generated from the calling method's namespace, class, and method name. Defaults to |
| | 181 | | ''' the current value of <see cref="SourceName"/>. |
| | 182 | | ''' </description> |
| | 183 | | ''' </item> |
| | 184 | | ''' |
| | 185 | | ''' <item> |
| | 186 | | ''' <term>EventLogHelper.MaxKilobytes</term> |
| | 187 | | ''' <description> |
| | 188 | | ''' The maximum size of the event log in kilobytes when creating a new log. |
| | 189 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 190 | | ''' Defaults to the current value of <see cref="MaxKilobytes"/> (normally 0). |
| | 191 | | ''' </description> |
| | 192 | | ''' </item> |
| | 193 | | ''' |
| | 194 | | ''' <item> |
| | 195 | | ''' <term>EventLogHelper.RetentionDays</term> |
| | 196 | | ''' <description> |
| | 197 | | ''' The number of days to retain event log entries when creating a new log. |
| | 198 | | ''' If 0, events are retained indefinitely. |
| | 199 | | ''' Defaults to the current value of <see cref="RetentionDays"/> (normally 0). |
| | 200 | | ''' </description> |
| | 201 | | ''' </item> |
| | 202 | | ''' |
| | 203 | | ''' <item> |
| | 204 | | ''' <term>EventLogHelper.WriteInitEntry</term> |
| | 205 | | ''' <description> |
| | 206 | | ''' Indicates whether to write an initialization entry to the log when a new log is created. |
| | 207 | | ''' Defaults to the current value of <see cref="WriteInitEntry"/> (normally True). |
| | 208 | | ''' </description> |
| | 209 | | ''' </item> |
| | 210 | | ''' |
| | 211 | | ''' <item> |
| | 212 | | ''' <term>EventLogHelper.TruncationMarker</term> |
| | 213 | | ''' <description> |
| | 214 | | ''' The string appended to messages that are truncated due to exceeding the 32,766-character limit. |
| | 215 | | ''' Defaults to the current value of <see cref="TruncationMarker"/> (normally "... [TRUNCATED]"). |
| | 216 | | ''' </description> |
| | 217 | | ''' </item> |
| | 218 | | ''' |
| | 219 | | ''' <item> |
| | 220 | | ''' <term>EventLogHelper.ContinuationMarker</term> |
| | 221 | | ''' <description> |
| | 222 | | ''' The string appended to all but the last chunk of a message when multi-entry logging is enabled. |
| | 223 | | ''' Defaults to the current value of <see cref="ContinuationMarker"/> (normally " ..."). |
| | 224 | | ''' </description> |
| | 225 | | ''' </item> |
| | 226 | | ''' |
| | 227 | | ''' <item> |
| | 228 | | ''' <term>EventLogHelper.AllowMultiEntryMessages</term> |
| | 229 | | ''' <description> |
| | 230 | | ''' Indicates whether messages longer than 32,766 characters should be split into multiple |
| | 231 | | ''' sequential entries instead of being truncated. Defaults to the current value of |
| | 232 | | ''' <see cref="AllowMultiEntryMessages"/> (normally False). |
| | 233 | | ''' </description> |
| | 234 | | ''' </item> |
| | 235 | | ''' |
| | 236 | | ''' </list> |
| | 237 | | ''' </remarks> |
| 8 | 238 | | Public Sub InitializeConfiguration() |
| | 239 | |
|
| 16 | 240 | | Initialize() |
| | 241 | |
|
| 16 | 242 | | End Sub |
| | 243 | |
|
| | 244 | | #End Region |
| | 245 | |
|
| | 246 | | #Region " Backing Fields ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 247 | |
|
| | 248 | | ''' <summary> |
| | 249 | | ''' The machine name |
| | 250 | | ''' </summary> |
| 8 | 251 | | Private _machineName As String = "." |
| | 252 | | ''' <summary> |
| | 253 | | ''' The log name |
| | 254 | | ''' </summary> |
| 8 | 255 | | Private _logName As String = "Application" |
| | 256 | | ''' <summary> |
| | 257 | | ''' The source name |
| | 258 | | ''' </summary> |
| 8 | 259 | | Private _sourceName As String = "" |
| | 260 | | ''' <summary> |
| | 261 | | ''' The maximum kilobytes |
| | 262 | | ''' </summary> |
| 8 | 263 | | Private _maxKilobytes As Integer = 1024 * 1024 |
| | 264 | | ''' <summary> |
| | 265 | | ''' The retention days |
| | 266 | | ''' </summary> |
| 8 | 267 | | Private _retentionDays As Integer = 7 |
| | 268 | | ''' <summary> |
| | 269 | | ''' The write initialize entry |
| | 270 | | ''' </summary> |
| 8 | 271 | | Private _writeInitEntry As Boolean = False |
| | 272 | | ''' <summary> |
| | 273 | | ''' The truncation marker |
| | 274 | | ''' </summary> |
| 8 | 275 | | Private _truncationMarker As String = "... [TRUNCATED]" |
| | 276 | | ''' <summary> |
| | 277 | | ''' The continuation marker |
| | 278 | | ''' </summary> |
| 8 | 279 | | Private _continuationMarker As String = " ..." |
| | 280 | | ''' <summary> |
| | 281 | | ''' The allow multi entry messages |
| | 282 | | ''' </summary> |
| 8 | 283 | | Private _allowMultiEntryMessages As Boolean = False |
| | 284 | |
|
| | 285 | | #End Region |
| | 286 | |
|
| | 287 | | #Region " Default Value Properties ^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 288 | |
|
| | 289 | | ''' <summary> |
| | 290 | | ''' Gets or sets the name of the machine where log entries will be written. |
| | 291 | | ''' </summary> |
| | 292 | | ''' <value> |
| | 293 | | ''' A string representing the machine name. Use <c>"."</c> for the local machine. |
| | 294 | | ''' </value> |
| | 295 | | Property MachineName As String |
| | 296 | |
|
| 234 | 297 | | Get |
| | 298 | |
|
| 468 | 299 | | Initialize() |
| 468 | 300 | | Return _machineName |
| | 301 | |
|
| 468 | 302 | | End Get |
| 32 | 303 | | Set |
| | 304 | |
|
| 64 | 305 | | Initialize() |
| 64 | 306 | | _machineName = Value |
| | 307 | |
|
| 64 | 308 | | End Set |
| | 309 | |
|
| | 310 | | End Property |
| | 311 | |
|
| | 312 | | ''' <summary> |
| | 313 | | ''' Gets or sets the name of the Windows Event Log to write to (e.g., "Application", "System"). |
| | 314 | | ''' </summary> |
| | 315 | | ''' <value> |
| | 316 | | ''' A string specifying the log name. Defaults to <c>"Application"</c>. |
| | 317 | | ''' </value> |
| | 318 | | Property LogName As String |
| | 319 | |
|
| 112 | 320 | | Get |
| | 321 | |
|
| 224 | 322 | | Initialize() |
| 224 | 323 | | Return _logName |
| | 324 | |
|
| 224 | 325 | | End Get |
| 16 | 326 | | Set |
| | 327 | |
|
| 32 | 328 | | Initialize() |
| 32 | 329 | | _logName = Value |
| | 330 | |
|
| 32 | 331 | | End Set |
| | 332 | |
|
| | 333 | | End Property |
| | 334 | |
|
| | 335 | | ''' <summary> |
| | 336 | | ''' Gets or sets the name of the event source associated with log entries. |
| | 337 | | ''' </summary> |
| | 338 | | ''' <value> |
| | 339 | | ''' A string representing the source name. If not set, a source is inferred automatically using the calling method's |
| | 340 | | ''' </value> |
| | 341 | | Property SourceName As String |
| | 342 | |
|
| 100 | 343 | | Get |
| | 344 | |
|
| 200 | 345 | | Initialize() |
| 200 | 346 | | Return _sourceName |
| | 347 | |
|
| 200 | 348 | | End Get |
| 28 | 349 | | Set |
| | 350 | |
|
| 56 | 351 | | Initialize() |
| 56 | 352 | | _sourceName = Value |
| | 353 | |
|
| 56 | 354 | | End Set |
| | 355 | |
|
| | 356 | | End Property |
| | 357 | |
|
| | 358 | | ''' <summary> |
| | 359 | | ''' Gets or sets the maximum allowed size of the event log in kilobytes. |
| | 360 | | ''' </summary> |
| | 361 | | ''' <value> |
| | 362 | | ''' An integer representing the size in kilobytes. Defaults to <c>1,048,576</c> (1 GB). |
| | 363 | | ''' </value> |
| | 364 | | ''' <remarks> |
| | 365 | | ''' Applies only when creating or configuring new custom logs. May require administrative privileges. |
| | 366 | | ''' </remarks> |
| | 367 | | Property MaxKilobytes As Integer |
| | 368 | |
|
| 136 | 369 | | Get |
| | 370 | |
|
| 272 | 371 | | Initialize() |
| 272 | 372 | | Return _maxKilobytes |
| | 373 | |
|
| 272 | 374 | | End Get |
| 16 | 375 | | Set |
| | 376 | |
|
| 32 | 377 | | Initialize() |
| 32 | 378 | | _maxKilobytes = Value |
| | 379 | |
|
| 32 | 380 | | End Set |
| | 381 | |
|
| | 382 | | End Property |
| | 383 | |
|
| | 384 | | ''' <summary> |
| | 385 | | ''' Gets or sets the number of days event entries are retained before being overwritten. |
| | 386 | | ''' </summary> |
| | 387 | | ''' <value> |
| | 388 | | ''' An integer representing the retention duration in days. Defaults to <c>7</c>. |
| | 389 | | ''' </value> |
| | 390 | | ''' <remarks> |
| | 391 | | ''' Used when initializing a new event log. May be ignored depending on overflow policy or system restrictions. |
| | 392 | | ''' </remarks> |
| | 393 | | Property RetentionDays As Integer |
| | 394 | |
|
| 140 | 395 | | Get |
| | 396 | |
|
| 280 | 397 | | Initialize() |
| 280 | 398 | | Return _retentionDays |
| | 399 | |
|
| 280 | 400 | | End Get |
| 16 | 401 | | Set |
| | 402 | |
|
| 32 | 403 | | Initialize() |
| 32 | 404 | | _retentionDays = Value |
| | 405 | |
|
| 32 | 406 | | End Set |
| | 407 | |
|
| | 408 | | End Property |
| | 409 | |
|
| | 410 | | ''' <summary> |
| | 411 | | ''' Gets or sets a value indicating whether an informational entry should be written when a new log is created. |
| | 412 | | ''' </summary> |
| | 413 | | ''' <value> |
| | 414 | | ''' <c>True</c> to log an initialization message; otherwise, <c>False</c>. Defaults to <c>False</c>. |
| | 415 | | ''' </value> |
| | 416 | | Property WriteInitEntry As Boolean |
| | 417 | |
|
| 144 | 418 | | Get |
| | 419 | |
|
| 288 | 420 | | Initialize() |
| 288 | 421 | | Return _writeInitEntry |
| | 422 | |
|
| 288 | 423 | | End Get |
| 16 | 424 | | Set |
| | 425 | |
|
| 32 | 426 | | Initialize() |
| 32 | 427 | | _writeInitEntry = Value |
| | 428 | |
|
| 32 | 429 | | End Set |
| | 430 | |
|
| | 431 | | End Property |
| | 432 | |
|
| | 433 | | ''' <summary> |
| | 434 | | ''' Gets or sets the marker text used when a message is too long and must be truncated. |
| | 435 | | ''' </summary> |
| | 436 | | ''' <value> |
| | 437 | | ''' A string appended to truncated log entries. Defaults to <c>"... [TRUNCATED]"</c>. |
| | 438 | | ''' </value> |
| | 439 | | Property TruncationMarker As String |
| | 440 | |
|
| 202 | 441 | | Get |
| | 442 | |
|
| 404 | 443 | | Initialize() |
| 404 | 444 | | Return _truncationMarker |
| | 445 | |
|
| 404 | 446 | | End Get |
| 16 | 447 | | Set |
| | 448 | |
|
| 32 | 449 | | Initialize() |
| 32 | 450 | | _truncationMarker = Value |
| | 451 | |
|
| 32 | 452 | | End Set |
| | 453 | |
|
| | 454 | | End Property |
| | 455 | |
|
| | 456 | | ''' <summary> |
| | 457 | | ''' Gets or sets the continuation marker used when splitting long messages |
| | 458 | | ''' across multiple event log entries. |
| | 459 | | ''' </summary> |
| | 460 | | ''' <value> |
| | 461 | | ''' The string appended to each intermediate log entry when |
| | 462 | | ''' <see cref="AllowMultiEntryMessages"/> is <c>true</c>. |
| | 463 | | ''' Defaults to <c>" ..."</c>. |
| | 464 | | ''' This value is ignored if message splitting is disabled. |
| | 465 | | ''' </value> |
| | 466 | | ''' <remarks> |
| | 467 | | ''' The marker is added to all chunks except the final one to indicate the |
| | 468 | | ''' message continues in the next log entry. Make sure the marker is short |
| | 469 | | ''' enough to allow meaningful message content within the 32,766-character |
| | 470 | | ''' limit of the Event Log. |
| | 471 | | ''' </remarks> |
| | 472 | | Property ContinuationMarker As String |
| | 473 | |
|
| 20 | 474 | | Get |
| | 475 | |
|
| 40 | 476 | | Initialize() |
| 40 | 477 | | Return _continuationMarker |
| | 478 | |
|
| 40 | 479 | | End Get |
| 20 | 480 | | Set |
| | 481 | |
|
| 40 | 482 | | Initialize() |
| 40 | 483 | | _continuationMarker = Value |
| | 484 | |
|
| 40 | 485 | | End Set |
| | 486 | |
|
| | 487 | | End Property |
| | 488 | |
|
| | 489 | | ''' <summary> |
| | 490 | | ''' Gets or sets a value indicating whether messages that exceed the Event Log |
| | 491 | | ''' length limit should be split across multiple entries. |
| | 492 | | ''' </summary> |
| | 493 | | ''' <value> |
| | 494 | | ''' <c>true</c> to split long messages into multiple event log entries; |
| | 495 | | ''' <c>false</c> to truncate long messages and append a truncation notice. |
| | 496 | | ''' Default is <c>false</c>. |
| | 497 | | ''' </value> |
| | 498 | | ''' <remarks> |
| | 499 | | ''' When enabled, messages exceeding 32,766 characters are split into sequential entries, |
| | 500 | | ''' each prefixed with a part number and optionally suffixed with a continuation marker |
| | 501 | | ''' (see <see cref="ContinuationMarker"/>). This preserves the full message without truncation. |
| | 502 | | ''' |
| | 503 | | ''' When disabled, long messages are truncated to fit within the Event Log limit, |
| | 504 | | ''' and the truncation marker (e.g., <c>"... [TRUNCATED]"</c>) is appended. |
| | 505 | | ''' </remarks> |
| | 506 | | Property AllowMultiEntryMessages As Boolean |
| | 507 | |
|
| 140 | 508 | | Get |
| | 509 | |
|
| 280 | 510 | | Initialize() |
| 280 | 511 | | Return _allowMultiEntryMessages |
| | 512 | |
|
| 280 | 513 | | End Get |
| 28 | 514 | | Set |
| | 515 | |
|
| 56 | 516 | | Initialize() |
| 56 | 517 | | _allowMultiEntryMessages = Value |
| | 518 | |
|
| 56 | 519 | | End Set |
| | 520 | |
|
| | 521 | | End Property |
| | 522 | |
|
| | 523 | | ''' <summary> |
| | 524 | | ''' Gets a value indicating whether this instance is initialized. |
| | 525 | | ''' </summary> |
| | 526 | | ''' <value> |
| | 527 | | ''' <c>true</c> if this instance is initialized; otherwise, <c>false</c>. |
| | 528 | | ''' </value> |
| | 529 | | Public ReadOnly Property IsInitialized As Boolean |
| | 530 | |
|
| 4 | 531 | | Get |
| 8 | 532 | | Return _isInitialized |
| | 533 | |
|
| 8 | 534 | | End Get |
| | 535 | |
|
| | 536 | | End Property |
| | 537 | |
|
| | 538 | | #End Region |
| | 539 | |
|
| | 540 | | #Region " Log Methods ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 541 | |
|
| | 542 | | ''' <summary> |
| | 543 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 544 | | ''' </summary> |
| | 545 | | ''' <param name="message"> |
| | 546 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 547 | | ''' |
| | 548 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 549 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 550 | | ''' |
| | 551 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 552 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 553 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 554 | | ''' </param> |
| | 555 | | ''' <remarks> |
| | 556 | | ''' <para> |
| | 557 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 558 | | ''' </para> |
| | 559 | | ''' <para> |
| | 560 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 561 | | ''' </para> |
| | 562 | | ''' </remarks> |
| 4 | 563 | | Public Sub Log( |
| 4 | 564 | | ByVal message As String) |
| | 565 | |
|
| 8 | 566 | | Log("", |
| 8 | 567 | | "", |
| 8 | 568 | | message) |
| | 569 | |
|
| 8 | 570 | | End Sub |
| | 571 | |
|
| | 572 | | ''' <summary> |
| | 573 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 574 | | ''' </summary> |
| | 575 | | ''' <param name="source"> |
| | 576 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 577 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 578 | | ''' </param> |
| | 579 | | ''' <param name="message"> |
| | 580 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 581 | | ''' |
| | 582 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 583 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 584 | | ''' |
| | 585 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 586 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 587 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 588 | | ''' </param> |
| | 589 | | ''' <remarks> |
| | 590 | | ''' <para> |
| | 591 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 592 | | ''' </para> |
| | 593 | | ''' <para> |
| | 594 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 595 | | ''' </para> |
| | 596 | | ''' </remarks> |
| 4 | 597 | | Public Sub Log( |
| 4 | 598 | | ByVal source As String, |
| 4 | 599 | | ByVal message As String) |
| | 600 | |
|
| 8 | 601 | | Log("", |
| 8 | 602 | | source, |
| 8 | 603 | | message) |
| | 604 | |
|
| 8 | 605 | | End Sub |
| | 606 | |
|
| | 607 | | ''' <summary> |
| | 608 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 609 | | ''' </summary> |
| | 610 | | ''' <param name="message"> |
| | 611 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 612 | | ''' |
| | 613 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 614 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 615 | | ''' |
| | 616 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 617 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 618 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 619 | | ''' </param> |
| | 620 | | ''' <param name="eventType"> |
| | 621 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 622 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 623 | | ''' </param> |
| | 624 | | ''' <remarks> |
| | 625 | | ''' <para> |
| | 626 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 627 | | ''' </para> |
| | 628 | | ''' <para> |
| | 629 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 630 | | ''' </para> |
| | 631 | | ''' </remarks> |
| 4 | 632 | | Public Sub Log( |
| 4 | 633 | | ByVal message As String, |
| 4 | 634 | | ByVal eventType As EventLogEntryType) |
| | 635 | |
|
| 8 | 636 | | Log("", |
| 8 | 637 | | message, |
| 8 | 638 | | eventType) |
| | 639 | |
|
| 8 | 640 | | End Sub |
| | 641 | |
|
| | 642 | | ''' <summary> |
| | 643 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 644 | | ''' </summary> |
| | 645 | | ''' <param name="logName"> |
| | 646 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 647 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 648 | | ''' </param> |
| | 649 | | ''' <param name="sourceName"> |
| | 650 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 651 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 652 | | ''' </param> |
| | 653 | | ''' <param name="message"> |
| | 654 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 655 | | ''' |
| | 656 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 657 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 658 | | ''' |
| | 659 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 660 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 661 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 662 | | ''' </param> |
| | 663 | | ''' <remarks> |
| | 664 | | ''' <para> |
| | 665 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 666 | | ''' </para> |
| | 667 | | ''' <para> |
| | 668 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 669 | | ''' </para> |
| | 670 | | ''' </remarks> |
| 12 | 671 | | Public Sub Log( |
| 12 | 672 | | ByVal logName As String, |
| 12 | 673 | | ByVal sourceName As String, |
| 12 | 674 | | ByVal message As String) |
| | 675 | |
|
| 24 | 676 | | Log(logName, |
| 24 | 677 | | sourceName, |
| 24 | 678 | | message, |
| 24 | 679 | | EventLogEntryType.Information) |
| | 680 | |
|
| 24 | 681 | | End Sub |
| | 682 | |
|
| | 683 | | ''' <summary> |
| | 684 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 685 | | ''' </summary> |
| | 686 | | ''' <param name="sourceName"> |
| | 687 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 688 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 689 | | ''' </param> |
| | 690 | | ''' <param name="message"> |
| | 691 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 692 | | ''' |
| | 693 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 694 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 695 | | ''' |
| | 696 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 697 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 698 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 699 | | ''' </param> |
| | 700 | | ''' <param name="eventType"> |
| | 701 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 702 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 703 | | ''' </param> |
| | 704 | | ''' <remarks> |
| | 705 | | ''' <para> |
| | 706 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 707 | | ''' </para> |
| | 708 | | ''' <para> |
| | 709 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 710 | | ''' </para> |
| | 711 | | ''' </remarks> |
| 8 | 712 | | Public Sub Log( |
| 8 | 713 | | ByVal sourceName As String, |
| 8 | 714 | | ByVal message As String, |
| 8 | 715 | | ByVal eventType As EventLogEntryType) |
| | 716 | |
|
| 16 | 717 | | Log("", |
| 16 | 718 | | sourceName, |
| 16 | 719 | | message, |
| 16 | 720 | | eventType) |
| | 721 | |
|
| 16 | 722 | | End Sub |
| | 723 | |
|
| | 724 | | ''' <summary> |
| | 725 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 726 | | ''' </summary> |
| | 727 | | ''' <param name="logName"> |
| | 728 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 729 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 730 | | ''' </param> |
| | 731 | | ''' <param name="sourceName"> |
| | 732 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 733 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 734 | | ''' </param> |
| | 735 | | ''' <param name="message"> |
| | 736 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 737 | | ''' |
| | 738 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 739 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 740 | | ''' |
| | 741 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 742 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 743 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 744 | | ''' </param> |
| | 745 | | ''' <param name="eventType"> |
| | 746 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 747 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 748 | | ''' </param> |
| | 749 | | ''' <remarks> |
| | 750 | | ''' <para> |
| | 751 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 752 | | ''' </para> |
| | 753 | | ''' <para> |
| | 754 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 755 | | ''' </para> |
| | 756 | | ''' </remarks> |
| 24 | 757 | | Public Sub Log( |
| 24 | 758 | | ByVal logName As String, |
| 24 | 759 | | ByVal sourceName As String, |
| 24 | 760 | | ByVal message As String, |
| 24 | 761 | | ByVal eventType As EventLogEntryType) |
| | 762 | |
|
| 48 | 763 | | Log(logName, |
| 48 | 764 | | sourceName, |
| 48 | 765 | | message, |
| 48 | 766 | | eventType, |
| 48 | 767 | | 0) |
| | 768 | |
|
| 48 | 769 | | End Sub |
| | 770 | |
|
| | 771 | | ''' <summary> |
| | 772 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 773 | | ''' </summary> |
| | 774 | | ''' <param name="message"> |
| | 775 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 776 | | ''' |
| | 777 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 778 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 779 | | ''' |
| | 780 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 781 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 782 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 783 | | ''' </param> |
| | 784 | | ''' <param name="eventType"> |
| | 785 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 786 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 787 | | ''' </param> |
| | 788 | | ''' <param name="eventID"> |
| | 789 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 790 | | ''' </param> |
| | 791 | | ''' <remarks> |
| | 792 | | ''' <para> |
| | 793 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 794 | | ''' </para> |
| | 795 | | ''' <para> |
| | 796 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 797 | | ''' </para> |
| | 798 | | ''' </remarks> |
| 4 | 799 | | Public Sub Log( |
| 4 | 800 | | ByVal message As String, |
| 4 | 801 | | ByVal eventType As EventLogEntryType, |
| 4 | 802 | | ByVal eventID As Integer) |
| | 803 | |
|
| 8 | 804 | | Log("", |
| 8 | 805 | | message, |
| 8 | 806 | | eventType, |
| 8 | 807 | | eventID) |
| | 808 | |
|
| 8 | 809 | | End Sub |
| | 810 | |
|
| | 811 | | ''' <summary> |
| | 812 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 813 | | ''' </summary> |
| | 814 | | ''' <param name="sourceName"> |
| | 815 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 816 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 817 | | ''' </param> |
| | 818 | | ''' <param name="message"> |
| | 819 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 820 | | ''' |
| | 821 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 822 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 823 | | ''' |
| | 824 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 825 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 826 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 827 | | ''' </param> |
| | 828 | | ''' <param name="eventType"> |
| | 829 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 830 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 831 | | ''' </param> |
| | 832 | | ''' <param name="eventID"> |
| | 833 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 834 | | ''' </param> |
| | 835 | | ''' <remarks> |
| | 836 | | ''' <para> |
| | 837 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 838 | | ''' </para> |
| | 839 | | ''' <para> |
| | 840 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 841 | | ''' </para> |
| | 842 | | ''' </remarks> |
| 4 | 843 | | Public Sub Log( |
| 4 | 844 | | ByVal sourceName As String, |
| 4 | 845 | | ByVal message As String, |
| 4 | 846 | | ByVal eventType As EventLogEntryType, |
| 4 | 847 | | ByVal eventID As Integer) |
| | 848 | |
|
| 8 | 849 | | Log("", |
| 8 | 850 | | sourceName, |
| 8 | 851 | | message, |
| 8 | 852 | | eventType, |
| 8 | 853 | | eventID) |
| | 854 | |
|
| 8 | 855 | | End Sub |
| | 856 | |
|
| | 857 | | ''' <summary> |
| | 858 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 859 | | ''' </summary> |
| | 860 | | ''' <param name="logName"> |
| | 861 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 862 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 863 | | ''' </param> |
| | 864 | | ''' <param name="sourceName"> |
| | 865 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 866 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 867 | | ''' </param> |
| | 868 | | ''' <param name="message"> |
| | 869 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 870 | | ''' |
| | 871 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 872 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 873 | | ''' |
| | 874 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 875 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 876 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 877 | | ''' </param> |
| | 878 | | ''' <param name="eventType"> |
| | 879 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 880 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 881 | | ''' </param> |
| | 882 | | ''' <param name="eventID"> |
| | 883 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 884 | | ''' </param> |
| | 885 | | ''' <remarks> |
| | 886 | | ''' <para> |
| | 887 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 888 | | ''' </para> |
| | 889 | | ''' <para> |
| | 890 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 891 | | ''' </para> |
| | 892 | | ''' </remarks> |
| 32 | 893 | | Public Sub Log( |
| 32 | 894 | | ByVal logName As String, |
| 32 | 895 | | ByVal sourceName As String, |
| 32 | 896 | | ByVal message As String, |
| 32 | 897 | | ByVal eventType As EventLogEntryType, |
| 32 | 898 | | ByVal eventID As Integer) |
| | 899 | |
|
| 64 | 900 | | Log(logName, |
| 64 | 901 | | sourceName, |
| 64 | 902 | | message, |
| 64 | 903 | | eventType, |
| 64 | 904 | | eventID, |
| 64 | 905 | | 0) |
| | 906 | |
|
| 64 | 907 | | End Sub |
| | 908 | |
|
| | 909 | | ''' <summary> |
| | 910 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 911 | | ''' </summary> |
| | 912 | | ''' <param name="message"> |
| | 913 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 914 | | ''' |
| | 915 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 916 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 917 | | ''' |
| | 918 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 919 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 920 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 921 | | ''' </param> |
| | 922 | | ''' <param name="eventType"> |
| | 923 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 924 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 925 | | ''' </param> |
| | 926 | | ''' <param name="eventID"> |
| | 927 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 928 | | ''' </param> |
| | 929 | | ''' <param name="category"> |
| | 930 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 931 | | ''' </param> |
| | 932 | | ''' <remarks> |
| | 933 | | ''' <para> |
| | 934 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 935 | | ''' </para> |
| | 936 | | ''' <para> |
| | 937 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 938 | | ''' </para> |
| | 939 | | ''' </remarks> |
| 4 | 940 | | Public Sub Log( |
| 4 | 941 | | ByVal message As String, |
| 4 | 942 | | ByVal eventType As EventLogEntryType, |
| 4 | 943 | | ByVal eventID As Integer, |
| 4 | 944 | | ByVal category As Short) |
| | 945 | |
|
| 8 | 946 | | Log("", |
| 8 | 947 | | message, |
| 8 | 948 | | eventType, |
| 8 | 949 | | eventID, |
| 8 | 950 | | category) |
| | 951 | |
|
| 8 | 952 | | End Sub |
| | 953 | |
|
| | 954 | | ''' <summary> |
| | 955 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 956 | | ''' </summary> |
| | 957 | | ''' <param name="sourceName"> |
| | 958 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 959 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 960 | | ''' </param> |
| | 961 | | ''' <param name="message"> |
| | 962 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 963 | | ''' |
| | 964 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 965 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 966 | | ''' |
| | 967 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 968 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 969 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 970 | | ''' </param> |
| | 971 | | ''' <param name="eventType"> |
| | 972 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 973 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 974 | | ''' </param> |
| | 975 | | ''' <param name="eventID"> |
| | 976 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 977 | | ''' </param> |
| | 978 | | ''' <param name="category"> |
| | 979 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 980 | | ''' </param> |
| | 981 | | ''' <remarks> |
| | 982 | | ''' <para> |
| | 983 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 984 | | ''' </para> |
| | 985 | | ''' <para> |
| | 986 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 987 | | ''' </para> |
| | 988 | | ''' </remarks> |
| 8 | 989 | | Public Sub Log( |
| 8 | 990 | | ByVal sourceName As String, |
| 8 | 991 | | ByVal message As String, |
| 8 | 992 | | ByVal eventType As EventLogEntryType, |
| 8 | 993 | | ByVal eventID As Integer, |
| 8 | 994 | | ByVal category As Short) |
| | 995 | |
|
| 16 | 996 | | Log("", |
| 16 | 997 | | sourceName, |
| 16 | 998 | | message, |
| 16 | 999 | | eventType, |
| 16 | 1000 | | eventID, |
| 16 | 1001 | | category) |
| | 1002 | |
|
| 16 | 1003 | | End Sub |
| | 1004 | |
|
| | 1005 | | ''' <summary> |
| | 1006 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1007 | | ''' </summary> |
| | 1008 | | ''' <param name="logName"> |
| | 1009 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 1010 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 1011 | | ''' </param> |
| | 1012 | | ''' <param name="sourceName"> |
| | 1013 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1014 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1015 | | ''' </param> |
| | 1016 | | ''' <param name="message"> |
| | 1017 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1018 | | ''' |
| | 1019 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1020 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1021 | | ''' |
| | 1022 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1023 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1024 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1025 | | ''' </param> |
| | 1026 | | ''' <param name="eventType"> |
| | 1027 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1028 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1029 | | ''' </param> |
| | 1030 | | ''' <param name="eventID"> |
| | 1031 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1032 | | ''' </param> |
| | 1033 | | ''' <param name="category"> |
| | 1034 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1035 | | ''' </param> |
| | 1036 | | ''' <remarks> |
| | 1037 | | ''' <para> |
| | 1038 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1039 | | ''' </para> |
| | 1040 | | ''' <para> |
| | 1041 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1042 | | ''' </para> |
| | 1043 | | ''' </remarks> |
| 44 | 1044 | | Public Sub Log( |
| 44 | 1045 | | ByVal logName As String, |
| 44 | 1046 | | ByVal sourceName As String, |
| 44 | 1047 | | ByVal message As String, |
| 44 | 1048 | | ByVal eventType As EventLogEntryType, |
| 44 | 1049 | | ByVal eventID As Integer, |
| 44 | 1050 | | ByVal category As Short) |
| | 1051 | |
|
| 88 | 1052 | | Log("", |
| 88 | 1053 | | logName, |
| 88 | 1054 | | sourceName, |
| 88 | 1055 | | message, |
| 88 | 1056 | | eventType, |
| 88 | 1057 | | eventID, |
| 88 | 1058 | | category, |
| 88 | 1059 | | Nothing) |
| | 1060 | |
|
| 88 | 1061 | | End Sub |
| | 1062 | |
|
| | 1063 | | ''' <summary> |
| | 1064 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1065 | | ''' </summary> |
| | 1066 | | ''' <param name="message"> |
| | 1067 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1068 | | ''' |
| | 1069 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1070 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1071 | | ''' |
| | 1072 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1073 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1074 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1075 | | ''' </param> |
| | 1076 | | ''' <param name="rawData"> |
| | 1077 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1078 | | ''' </param> |
| | 1079 | | ''' <remarks> |
| | 1080 | | ''' <para> |
| | 1081 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1082 | | ''' </para> |
| | 1083 | | ''' <para> |
| | 1084 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1085 | | ''' </para> |
| | 1086 | | ''' </remarks> |
| 4 | 1087 | | Public Sub Log( |
| 4 | 1088 | | ByVal message As String, |
| 4 | 1089 | | ByVal rawData As Byte()) |
| | 1090 | |
|
| 8 | 1091 | | Log(message, |
| 8 | 1092 | | EventLogEntryType.Information, |
| 8 | 1093 | | rawData) |
| | 1094 | |
|
| 8 | 1095 | | End Sub |
| | 1096 | |
|
| | 1097 | | ''' <summary> |
| | 1098 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1099 | | ''' </summary> |
| | 1100 | | ''' <param name="message"> |
| | 1101 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1102 | | ''' |
| | 1103 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1104 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1105 | | ''' |
| | 1106 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1107 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1108 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1109 | | ''' </param> |
| | 1110 | | ''' <param name="eventType"> |
| | 1111 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1112 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1113 | | ''' </param> |
| | 1114 | | ''' <param name="rawData"> |
| | 1115 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1116 | | ''' </param> |
| | 1117 | | ''' <remarks> |
| | 1118 | | ''' <para> |
| | 1119 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1120 | | ''' </para> |
| | 1121 | | ''' <para> |
| | 1122 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1123 | | ''' </para> |
| | 1124 | | ''' </remarks> |
| 8 | 1125 | | Public Sub Log( |
| 8 | 1126 | | ByVal message As String, |
| 8 | 1127 | | ByVal eventType As EventLogEntryType, |
| 8 | 1128 | | ByVal rawData As Byte()) |
| | 1129 | |
|
| 16 | 1130 | | Log(message, |
| 16 | 1131 | | eventType, |
| 16 | 1132 | | 0, |
| 16 | 1133 | | rawData) |
| | 1134 | |
|
| 16 | 1135 | | End Sub |
| | 1136 | |
|
| | 1137 | | ''' <summary> |
| | 1138 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1139 | | ''' </summary> |
| | 1140 | | ''' <param name="message"> |
| | 1141 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1142 | | ''' |
| | 1143 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1144 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1145 | | ''' |
| | 1146 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1147 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1148 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1149 | | ''' </param> |
| | 1150 | | ''' <param name="eventType"> |
| | 1151 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1152 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1153 | | ''' </param> |
| | 1154 | | ''' <param name="eventID"> |
| | 1155 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1156 | | ''' </param> |
| | 1157 | | ''' <param name="rawData"> |
| | 1158 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1159 | | ''' </param> |
| | 1160 | | ''' <remarks> |
| | 1161 | | ''' <para> |
| | 1162 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1163 | | ''' </para> |
| | 1164 | | ''' <para> |
| | 1165 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1166 | | ''' </para> |
| | 1167 | | ''' </remarks> |
| 12 | 1168 | | Public Sub Log( |
| 12 | 1169 | | ByVal message As String, |
| 12 | 1170 | | ByVal eventType As EventLogEntryType, |
| 12 | 1171 | | ByVal eventID As Integer, |
| 12 | 1172 | | ByVal rawData As Byte()) |
| | 1173 | |
|
| 24 | 1174 | | Log(message, |
| 24 | 1175 | | eventType, |
| 24 | 1176 | | eventID, |
| 24 | 1177 | | 0, |
| 24 | 1178 | | rawData) |
| | 1179 | |
|
| 24 | 1180 | | End Sub |
| | 1181 | |
|
| | 1182 | | ''' <summary> |
| | 1183 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1184 | | ''' </summary> |
| | 1185 | | ''' <param name="message"> |
| | 1186 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1187 | | ''' |
| | 1188 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1189 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1190 | | ''' |
| | 1191 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1192 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1193 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1194 | | ''' </param> |
| | 1195 | | ''' <param name="eventType"> |
| | 1196 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1197 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1198 | | ''' </param> |
| | 1199 | | ''' <param name="eventID"> |
| | 1200 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1201 | | ''' </param> |
| | 1202 | | ''' <param name="category"> |
| | 1203 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1204 | | ''' </param> |
| | 1205 | | ''' <param name="rawData"> |
| | 1206 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1207 | | ''' </param> |
| | 1208 | | ''' <remarks> |
| | 1209 | | ''' <para> |
| | 1210 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1211 | | ''' </para> |
| | 1212 | | ''' <para> |
| | 1213 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1214 | | ''' </para> |
| | 1215 | | ''' </remarks> |
| 16 | 1216 | | Public Sub Log( |
| 16 | 1217 | | ByVal message As String, |
| 16 | 1218 | | ByVal eventType As EventLogEntryType, |
| 16 | 1219 | | ByVal eventID As Integer, |
| 16 | 1220 | | ByVal category As Short, |
| 16 | 1221 | | ByVal rawData As Byte()) |
| | 1222 | |
|
| 32 | 1223 | | Log("", |
| 32 | 1224 | | "", |
| 32 | 1225 | | "", |
| 32 | 1226 | | message, |
| 32 | 1227 | | eventType, |
| 32 | 1228 | | eventID, |
| 32 | 1229 | | category, |
| 32 | 1230 | | rawData) |
| | 1231 | |
|
| 32 | 1232 | | End Sub |
| | 1233 | |
|
| | 1234 | | ''' <summary> |
| | 1235 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1236 | | ''' </summary> |
| | 1237 | | ''' <param name="sourceName"> |
| | 1238 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1239 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1240 | | ''' </param> |
| | 1241 | | ''' <param name="message"> |
| | 1242 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1243 | | ''' |
| | 1244 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1245 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1246 | | ''' |
| | 1247 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1248 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1249 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1250 | | ''' </param> |
| | 1251 | | ''' <param name="eventType"> |
| | 1252 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1253 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1254 | | ''' </param> |
| | 1255 | | ''' <param name="eventID"> |
| | 1256 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1257 | | ''' </param> |
| | 1258 | | ''' <param name="category"> |
| | 1259 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1260 | | ''' </param> |
| | 1261 | | ''' <param name="rawData"> |
| | 1262 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1263 | | ''' </param> |
| | 1264 | | ''' <remarks> |
| | 1265 | | ''' <para> |
| | 1266 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1267 | | ''' </para> |
| | 1268 | | ''' <para> |
| | 1269 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1270 | | ''' </para> |
| | 1271 | | ''' </remarks> |
| 4 | 1272 | | Public Sub Log( |
| 4 | 1273 | | ByVal sourceName As String, |
| 4 | 1274 | | ByVal message As String, |
| 4 | 1275 | | ByVal eventType As EventLogEntryType, |
| 4 | 1276 | | ByVal eventID As Integer, |
| 4 | 1277 | | ByVal category As Short, |
| 4 | 1278 | | ByVal rawData As Byte()) |
| | 1279 | |
|
| 8 | 1280 | | Log("", |
| 8 | 1281 | | "", |
| 8 | 1282 | | sourceName, |
| 8 | 1283 | | message, |
| 8 | 1284 | | eventType, |
| 8 | 1285 | | eventID, |
| 8 | 1286 | | category, |
| 8 | 1287 | | rawData) |
| | 1288 | |
|
| 8 | 1289 | | End Sub |
| | 1290 | |
|
| | 1291 | | ''' <summary> |
| | 1292 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1293 | | ''' </summary> |
| | 1294 | | ''' <param name="logName"> |
| | 1295 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 1296 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 1297 | | ''' </param> |
| | 1298 | | ''' <param name="source"> |
| | 1299 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1300 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1301 | | ''' </param> |
| | 1302 | | ''' <param name="message"> |
| | 1303 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1304 | | ''' |
| | 1305 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1306 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1307 | | ''' |
| | 1308 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1309 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1310 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1311 | | ''' </param> |
| | 1312 | | ''' <param name="eventType"> |
| | 1313 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1314 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1315 | | ''' </param> |
| | 1316 | | ''' <param name="eventID"> |
| | 1317 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1318 | | ''' </param> |
| | 1319 | | ''' <param name="category"> |
| | 1320 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1321 | | ''' </param> |
| | 1322 | | ''' <param name="rawData"> |
| | 1323 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1324 | | ''' </param> |
| | 1325 | | ''' <remarks> |
| | 1326 | | ''' <para> |
| | 1327 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1328 | | ''' </para> |
| | 1329 | | ''' <para> |
| | 1330 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1331 | | ''' </para> |
| | 1332 | | ''' </remarks> |
| 32 | 1333 | | Public Sub Log( |
| 32 | 1334 | | ByVal logName As String, |
| 32 | 1335 | | ByVal source As String, |
| 32 | 1336 | | ByVal message As String, |
| 32 | 1337 | | ByVal eventType As EventLogEntryType, |
| 32 | 1338 | | ByVal eventID As Integer, |
| 32 | 1339 | | ByVal category As Short, |
| 32 | 1340 | | ByVal rawData As Byte()) |
| | 1341 | |
|
| 64 | 1342 | | Log( |
| 64 | 1343 | | "", |
| 64 | 1344 | | logName, |
| 64 | 1345 | | source, |
| 64 | 1346 | | message, |
| 64 | 1347 | | eventType, |
| 64 | 1348 | | eventID, |
| 64 | 1349 | | category, |
| 64 | 1350 | | rawData) |
| | 1351 | |
|
| 64 | 1352 | | End Sub |
| | 1353 | |
|
| | 1354 | | ''' <summary> |
| | 1355 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1356 | | ''' </summary> |
| | 1357 | | ''' <param name="logName"> |
| | 1358 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 1359 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 1360 | | ''' </param> |
| | 1361 | | ''' <param name="source"> |
| | 1362 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1363 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1364 | | ''' </param> |
| | 1365 | | ''' <param name="message"> |
| | 1366 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1367 | | ''' |
| | 1368 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1369 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1370 | | ''' |
| | 1371 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1372 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1373 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1374 | | ''' </param> |
| | 1375 | | ''' <param name="eventType"> |
| | 1376 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1377 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1378 | | ''' </param> |
| | 1379 | | ''' <param name="eventID"> |
| | 1380 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1381 | | ''' </param> |
| | 1382 | | ''' <param name="category"> |
| | 1383 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1384 | | ''' </param> |
| | 1385 | | ''' <param name="rawData"> |
| | 1386 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1387 | | ''' </param> |
| | 1388 | | ''' <remarks> |
| | 1389 | | ''' <para> |
| | 1390 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1391 | | ''' </para> |
| | 1392 | | ''' <para> |
| | 1393 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1394 | | ''' </para> |
| | 1395 | | ''' </remarks> |
| 96 | 1396 | | Public Sub Log( |
| 96 | 1397 | | ByVal machineName As String, |
| 96 | 1398 | | ByVal logName As String, |
| 96 | 1399 | | ByVal source As String, |
| 96 | 1400 | | ByVal message As String, |
| 96 | 1401 | | ByVal eventType As EventLogEntryType, |
| 96 | 1402 | | ByVal eventID As Integer, |
| 96 | 1403 | | ByVal category As Short, |
| 96 | 1404 | | ByVal rawData As Byte()) |
| | 1405 | |
|
| 192 | 1406 | | Initialize() |
| 192 | 1407 | | Log( |
| 192 | 1408 | | machineName, |
| 192 | 1409 | | logName, |
| 192 | 1410 | | source, |
| 192 | 1411 | | message, |
| 192 | 1412 | | eventType, |
| 192 | 1413 | | eventID, |
| 192 | 1414 | | category, |
| 192 | 1415 | | rawData, |
| 192 | 1416 | | MaxKilobytes) |
| | 1417 | |
|
| 192 | 1418 | | End Sub |
| | 1419 | |
|
| | 1420 | | ''' <summary> |
| | 1421 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1422 | | ''' </summary> |
| | 1423 | | ''' <param name="logName"> |
| | 1424 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 1425 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 1426 | | ''' </param> |
| | 1427 | | ''' <param name="source"> |
| | 1428 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1429 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1430 | | ''' </param> |
| | 1431 | | ''' <param name="message"> |
| | 1432 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1433 | | ''' |
| | 1434 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1435 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1436 | | ''' |
| | 1437 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1438 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1439 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1440 | | ''' </param> |
| | 1441 | | ''' <param name="eventType"> |
| | 1442 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1443 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1444 | | ''' </param> |
| | 1445 | | ''' <param name="eventID"> |
| | 1446 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1447 | | ''' </param> |
| | 1448 | | ''' <param name="category"> |
| | 1449 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1450 | | ''' </param> |
| | 1451 | | ''' <param name="rawData"> |
| | 1452 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1453 | | ''' </param> |
| | 1454 | | ''' <param name="maxKilobytes"> |
| | 1455 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1456 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1457 | | ''' </param> |
| | 1458 | | ''' <remarks> |
| | 1459 | | ''' <para> |
| | 1460 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1461 | | ''' </para> |
| | 1462 | | ''' <para> |
| | 1463 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1464 | | ''' </para> |
| | 1465 | | ''' </remarks> |
| 96 | 1466 | | Public Sub Log( |
| 96 | 1467 | | ByVal machineName As String, |
| 96 | 1468 | | ByVal logName As String, |
| 96 | 1469 | | ByVal source As String, |
| 96 | 1470 | | ByVal message As String, |
| 96 | 1471 | | ByVal eventType As EventLogEntryType, |
| 96 | 1472 | | ByVal eventID As Integer, |
| 96 | 1473 | | ByVal category As Short, |
| 96 | 1474 | | ByVal rawData As Byte(), |
| 96 | 1475 | | ByVal maxKilobytes As Integer) |
| | 1476 | |
|
| 192 | 1477 | | Initialize() |
| 192 | 1478 | | Log( |
| 192 | 1479 | | machineName, |
| 192 | 1480 | | logName, |
| 192 | 1481 | | source, |
| 192 | 1482 | | message, |
| 192 | 1483 | | eventType, |
| 192 | 1484 | | eventID, |
| 192 | 1485 | | category, |
| 192 | 1486 | | rawData, |
| 192 | 1487 | | maxKilobytes, |
| 192 | 1488 | | RetentionDays) |
| | 1489 | |
|
| 192 | 1490 | | End Sub |
| | 1491 | |
|
| | 1492 | | ''' <summary> |
| | 1493 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1494 | | ''' </summary> |
| | 1495 | | ''' <param name="message"> |
| | 1496 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1497 | | ''' |
| | 1498 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1499 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1500 | | ''' |
| | 1501 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1502 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1503 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1504 | | ''' </param> |
| | 1505 | | ''' <param name="maxKilobytes"> |
| | 1506 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1507 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1508 | | ''' </param> |
| | 1509 | | ''' <param name="retentionDays"> |
| | 1510 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1511 | | ''' Only used when creating a new log. |
| | 1512 | | ''' </param> |
| | 1513 | | ''' <remarks> |
| | 1514 | | ''' <para> |
| | 1515 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1516 | | ''' </para> |
| | 1517 | | ''' <para> |
| | 1518 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1519 | | ''' </para> |
| | 1520 | | ''' </remarks> |
| 4 | 1521 | | Public Sub Log( |
| 4 | 1522 | | ByVal message As String, |
| 4 | 1523 | | ByVal maxKilobytes As Integer, |
| 4 | 1524 | | ByVal retentionDays As Integer) |
| | 1525 | |
|
| 8 | 1526 | | Log( |
| 8 | 1527 | | message, |
| 8 | 1528 | | EventLogEntryType.Information, |
| 8 | 1529 | | maxKilobytes, |
| 8 | 1530 | | retentionDays) |
| | 1531 | |
|
| 8 | 1532 | | End Sub |
| | 1533 | |
|
| | 1534 | | ''' <summary> |
| | 1535 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1536 | | ''' </summary> |
| | 1537 | | ''' <param name="message"> |
| | 1538 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1539 | | ''' |
| | 1540 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1541 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1542 | | ''' |
| | 1543 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1544 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1545 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1546 | | ''' </param> |
| | 1547 | | ''' <param name="eventType"> |
| | 1548 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1549 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1550 | | ''' </param> |
| | 1551 | | ''' <param name="maxKilobytes"> |
| | 1552 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1553 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1554 | | ''' </param> |
| | 1555 | | ''' <param name="retentionDays"> |
| | 1556 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1557 | | ''' Only used when creating a new log. |
| | 1558 | | ''' </param> |
| | 1559 | | ''' <remarks> |
| | 1560 | | ''' <para> |
| | 1561 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1562 | | ''' </para> |
| | 1563 | | ''' <para> |
| | 1564 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1565 | | ''' </para> |
| | 1566 | | ''' </remarks> |
| 4 | 1567 | | Public Sub Log( |
| 4 | 1568 | | ByVal message As String, |
| 4 | 1569 | | ByVal eventType As EventLogEntryType, |
| 4 | 1570 | | ByVal maxKilobytes As Integer, |
| 4 | 1571 | | ByVal retentionDays As Integer) |
| | 1572 | |
|
| 8 | 1573 | | Log( |
| 8 | 1574 | | message, |
| 8 | 1575 | | eventType, |
| 8 | 1576 | | 0, |
| 8 | 1577 | | maxKilobytes, |
| 8 | 1578 | | retentionDays) |
| | 1579 | |
|
| 8 | 1580 | | End Sub |
| | 1581 | |
|
| | 1582 | | ''' <summary> |
| | 1583 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1584 | | ''' </summary> |
| | 1585 | | ''' <param name="message"> |
| | 1586 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1587 | | ''' |
| | 1588 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1589 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1590 | | ''' |
| | 1591 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1592 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1593 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1594 | | ''' </param> |
| | 1595 | | ''' <param name="eventType"> |
| | 1596 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1597 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1598 | | ''' </param> |
| | 1599 | | ''' <param name="eventID"> |
| | 1600 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1601 | | ''' </param> |
| | 1602 | | ''' <param name="maxKilobytes"> |
| | 1603 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1604 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1605 | | ''' </param> |
| | 1606 | | ''' <param name="retentionDays"> |
| | 1607 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1608 | | ''' Only used when creating a new log. |
| | 1609 | | ''' </param> |
| | 1610 | | ''' <remarks> |
| | 1611 | | ''' <para> |
| | 1612 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1613 | | ''' </para> |
| | 1614 | | ''' <para> |
| | 1615 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1616 | | ''' </para> |
| | 1617 | | ''' </remarks> |
| 4 | 1618 | | Public Sub Log( |
| 4 | 1619 | | ByVal message As String, |
| 4 | 1620 | | ByVal eventType As EventLogEntryType, |
| 4 | 1621 | | ByVal eventID As Integer, |
| 4 | 1622 | | ByVal maxKilobytes As Integer, |
| 4 | 1623 | | ByVal retentionDays As Integer) |
| | 1624 | |
|
| 8 | 1625 | | Log( |
| 8 | 1626 | | message, |
| 8 | 1627 | | eventType, |
| 8 | 1628 | | eventID, |
| 8 | 1629 | | 0, |
| 8 | 1630 | | maxKilobytes, |
| 8 | 1631 | | retentionDays) |
| | 1632 | |
|
| 8 | 1633 | | End Sub |
| | 1634 | |
|
| | 1635 | | ''' <summary> |
| | 1636 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1637 | | ''' </summary> |
| | 1638 | | ''' <param name="message"> |
| | 1639 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1640 | | ''' |
| | 1641 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1642 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1643 | | ''' |
| | 1644 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1645 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1646 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1647 | | ''' </param> |
| | 1648 | | ''' <param name="eventType"> |
| | 1649 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1650 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1651 | | ''' </param> |
| | 1652 | | ''' <param name="eventID"> |
| | 1653 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1654 | | ''' </param> |
| | 1655 | | ''' <param name="category"> |
| | 1656 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1657 | | ''' </param> |
| | 1658 | | ''' <param name="maxKilobytes"> |
| | 1659 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1660 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1661 | | ''' </param> |
| | 1662 | | ''' <param name="retentionDays"> |
| | 1663 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1664 | | ''' Only used when creating a new log. |
| | 1665 | | ''' </param> |
| | 1666 | | ''' <remarks> |
| | 1667 | | ''' <para> |
| | 1668 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1669 | | ''' </para> |
| | 1670 | | ''' <para> |
| | 1671 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1672 | | ''' </para> |
| | 1673 | | ''' </remarks> |
| 4 | 1674 | | Public Sub Log( |
| 4 | 1675 | | ByVal message As String, |
| 4 | 1676 | | ByVal eventType As EventLogEntryType, |
| 4 | 1677 | | ByVal eventID As Integer, |
| 4 | 1678 | | ByVal category As Short, |
| 4 | 1679 | | ByVal maxKilobytes As Integer, |
| 4 | 1680 | | ByVal retentionDays As Integer) |
| | 1681 | |
|
| 8 | 1682 | | Log( |
| 8 | 1683 | | message, |
| 8 | 1684 | | eventType, |
| 8 | 1685 | | eventID, |
| 8 | 1686 | | category, |
| 8 | 1687 | | Nothing, |
| 8 | 1688 | | maxKilobytes, |
| 8 | 1689 | | retentionDays) |
| | 1690 | |
|
| 8 | 1691 | | End Sub |
| | 1692 | |
|
| | 1693 | | ''' <summary> |
| | 1694 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1695 | | ''' </summary> |
| | 1696 | | ''' <param name="message"> |
| | 1697 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1698 | | ''' |
| | 1699 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1700 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1701 | | ''' |
| | 1702 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1703 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1704 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1705 | | ''' </param> |
| | 1706 | | ''' <param name="eventType"> |
| | 1707 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1708 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1709 | | ''' </param> |
| | 1710 | | ''' <param name="eventID"> |
| | 1711 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1712 | | ''' </param> |
| | 1713 | | ''' <param name="category"> |
| | 1714 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1715 | | ''' </param> |
| | 1716 | | ''' <param name="rawData"> |
| | 1717 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1718 | | ''' </param> |
| | 1719 | | ''' <param name="maxKilobytes"> |
| | 1720 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1721 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1722 | | ''' </param> |
| | 1723 | | ''' <param name="retentionDays"> |
| | 1724 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1725 | | ''' Only used when creating a new log. |
| | 1726 | | ''' </param> |
| | 1727 | | ''' <remarks> |
| | 1728 | | ''' <para> |
| | 1729 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1730 | | ''' </para> |
| | 1731 | | ''' <para> |
| | 1732 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1733 | | ''' </para> |
| | 1734 | | ''' </remarks> |
| 4 | 1735 | | Public Sub Log( |
| 4 | 1736 | | ByVal message As String, |
| 4 | 1737 | | ByVal eventType As EventLogEntryType, |
| 4 | 1738 | | ByVal eventID As Integer, |
| 4 | 1739 | | ByVal category As Short, |
| 4 | 1740 | | ByVal rawData As Byte(), |
| 4 | 1741 | | ByVal maxKilobytes As Integer, |
| 4 | 1742 | | ByVal retentionDays As Integer) |
| | 1743 | |
|
| 8 | 1744 | | Log( |
| 8 | 1745 | | "", |
| 8 | 1746 | | message, |
| 8 | 1747 | | eventType, |
| 8 | 1748 | | eventID, |
| 8 | 1749 | | category, |
| 8 | 1750 | | rawData, |
| 8 | 1751 | | maxKilobytes, |
| 8 | 1752 | | retentionDays) |
| | 1753 | |
|
| 8 | 1754 | | End Sub |
| | 1755 | |
|
| | 1756 | | ''' <summary> |
| | 1757 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1758 | | ''' </summary> |
| | 1759 | | ''' <param name="source"> |
| | 1760 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1761 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1762 | | ''' </param> |
| | 1763 | | ''' <param name="message"> |
| | 1764 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1765 | | ''' |
| | 1766 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1767 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1768 | | ''' |
| | 1769 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1770 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1771 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1772 | | ''' </param> |
| | 1773 | | ''' <param name="eventType"> |
| | 1774 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1775 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1776 | | ''' </param> |
| | 1777 | | ''' <param name="eventID"> |
| | 1778 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1779 | | ''' </param> |
| | 1780 | | ''' <param name="category"> |
| | 1781 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1782 | | ''' </param> |
| | 1783 | | ''' <param name="rawData"> |
| | 1784 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1785 | | ''' </param> |
| | 1786 | | ''' <param name="maxKilobytes"> |
| | 1787 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1788 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1789 | | ''' </param> |
| | 1790 | | ''' <param name="retentionDays"> |
| | 1791 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1792 | | ''' Only used when creating a new log. |
| | 1793 | | ''' </param> |
| | 1794 | | ''' <remarks> |
| | 1795 | | ''' <para> |
| | 1796 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1797 | | ''' </para> |
| | 1798 | | ''' <para> |
| | 1799 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1800 | | ''' </para> |
| | 1801 | | ''' </remarks> |
| 4 | 1802 | | Public Sub Log( |
| 4 | 1803 | | ByVal source As String, |
| 4 | 1804 | | ByVal message As String, |
| 4 | 1805 | | ByVal eventType As EventLogEntryType, |
| 4 | 1806 | | ByVal eventID As Integer, |
| 4 | 1807 | | ByVal category As Short, |
| 4 | 1808 | | ByVal rawData As Byte(), |
| 4 | 1809 | | ByVal maxKilobytes As Integer, |
| 4 | 1810 | | ByVal retentionDays As Integer) |
| | 1811 | |
|
| 8 | 1812 | | Log( |
| 8 | 1813 | | "", |
| 8 | 1814 | | source, |
| 8 | 1815 | | message, |
| 8 | 1816 | | eventType, |
| 8 | 1817 | | eventID, |
| 8 | 1818 | | category, |
| 8 | 1819 | | rawData, |
| 8 | 1820 | | maxKilobytes, |
| 8 | 1821 | | retentionDays) |
| | 1822 | |
|
| 8 | 1823 | | End Sub |
| | 1824 | |
|
| | 1825 | | ''' <summary> |
| | 1826 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1827 | | ''' </summary> |
| | 1828 | | ''' <param name="logName"> |
| | 1829 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 1830 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 1831 | | ''' </param> |
| | 1832 | | ''' <param name="source"> |
| | 1833 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1834 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1835 | | ''' </param> |
| | 1836 | | ''' <param name="message"> |
| | 1837 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1838 | | ''' |
| | 1839 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1840 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1841 | | ''' |
| | 1842 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1843 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1844 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1845 | | ''' </param> |
| | 1846 | | ''' <param name="eventType"> |
| | 1847 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1848 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1849 | | ''' </param> |
| | 1850 | | ''' <param name="eventID"> |
| | 1851 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1852 | | ''' </param> |
| | 1853 | | ''' <param name="category"> |
| | 1854 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1855 | | ''' </param> |
| | 1856 | | ''' <param name="rawData"> |
| | 1857 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1858 | | ''' </param> |
| | 1859 | | ''' <param name="maxKilobytes"> |
| | 1860 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1861 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1862 | | ''' </param> |
| | 1863 | | ''' <param name="retentionDays"> |
| | 1864 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1865 | | ''' Only used when creating a new log. |
| | 1866 | | ''' </param> |
| | 1867 | | ''' <remarks> |
| | 1868 | | ''' <para> |
| | 1869 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1870 | | ''' </para> |
| | 1871 | | ''' <para> |
| | 1872 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1873 | | ''' </para> |
| | 1874 | | ''' </remarks> |
| 4 | 1875 | | Public Sub Log( |
| 4 | 1876 | | ByVal logName As String, |
| 4 | 1877 | | ByVal source As String, |
| 4 | 1878 | | ByVal message As String, |
| 4 | 1879 | | ByVal eventType As EventLogEntryType, |
| 4 | 1880 | | ByVal eventID As Integer, |
| 4 | 1881 | | ByVal category As Short, |
| 4 | 1882 | | ByVal rawData As Byte(), |
| 4 | 1883 | | ByVal maxKilobytes As Integer, |
| 4 | 1884 | | ByVal retentionDays As Integer) |
| | 1885 | |
|
| 8 | 1886 | | Log( |
| 8 | 1887 | | "", |
| 8 | 1888 | | logName, |
| 8 | 1889 | | source, |
| 8 | 1890 | | message, |
| 8 | 1891 | | eventType, |
| 8 | 1892 | | eventID, |
| 8 | 1893 | | category, |
| 8 | 1894 | | rawData, |
| 8 | 1895 | | maxKilobytes, |
| 8 | 1896 | | retentionDays) |
| | 1897 | |
|
| 8 | 1898 | | End Sub |
| | 1899 | |
|
| | 1900 | | ''' <summary> |
| | 1901 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1902 | | ''' </summary> |
| | 1903 | | ''' <param name="logName"> |
| | 1904 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 1905 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 1906 | | ''' </param> |
| | 1907 | | ''' <param name="source"> |
| | 1908 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 1909 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 1910 | | ''' </param> |
| | 1911 | | ''' <param name="message"> |
| | 1912 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1913 | | ''' |
| | 1914 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1915 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1916 | | ''' |
| | 1917 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1918 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1919 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1920 | | ''' </param> |
| | 1921 | | ''' <param name="eventType"> |
| | 1922 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 1923 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 1924 | | ''' </param> |
| | 1925 | | ''' <param name="eventID"> |
| | 1926 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 1927 | | ''' </param> |
| | 1928 | | ''' <param name="category"> |
| | 1929 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 1930 | | ''' </param> |
| | 1931 | | ''' <param name="rawData"> |
| | 1932 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 1933 | | ''' </param> |
| | 1934 | | ''' <param name="maxKilobytes"> |
| | 1935 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1936 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1937 | | ''' </param> |
| | 1938 | | ''' <param name="retentionDays"> |
| | 1939 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1940 | | ''' Only used when creating a new log. |
| | 1941 | | ''' </param> |
| | 1942 | | ''' <remarks> |
| | 1943 | | ''' <para> |
| | 1944 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 1945 | | ''' </para> |
| | 1946 | | ''' <para> |
| | 1947 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 1948 | | ''' </para> |
| | 1949 | | ''' </remarks> |
| 100 | 1950 | | Public Sub Log( |
| 100 | 1951 | | ByVal machineName As String, |
| 100 | 1952 | | ByVal logName As String, |
| 100 | 1953 | | ByVal source As String, |
| 100 | 1954 | | ByVal message As String, |
| 100 | 1955 | | ByVal eventType As EventLogEntryType, |
| 100 | 1956 | | ByVal eventID As Integer, |
| 100 | 1957 | | ByVal category As Short, |
| 100 | 1958 | | ByVal rawData As Byte(), |
| 100 | 1959 | | ByVal maxKilobytes As Integer, |
| 100 | 1960 | | ByVal retentionDays As Integer) |
| | 1961 | |
|
| 200 | 1962 | | Initialize() |
| | 1963 | |
|
| 200 | 1964 | | Log( |
| 200 | 1965 | | machineName, |
| 200 | 1966 | | logName, |
| 200 | 1967 | | source, |
| 200 | 1968 | | message, |
| 200 | 1969 | | eventType, |
| 200 | 1970 | | eventID, |
| 200 | 1971 | | category, |
| 200 | 1972 | | rawData, |
| 200 | 1973 | | maxKilobytes, |
| 200 | 1974 | | retentionDays, |
| 200 | 1975 | | WriteInitEntry) |
| | 1976 | |
|
| 200 | 1977 | | End Sub |
| | 1978 | |
|
| | 1979 | | ''' <summary> |
| | 1980 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 1981 | | ''' </summary> |
| | 1982 | | ''' <param name="message"> |
| | 1983 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 1984 | | ''' |
| | 1985 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 1986 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 1987 | | ''' |
| | 1988 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 1989 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 1990 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 1991 | | ''' </param> |
| | 1992 | | ''' <param name="maxKilobytes"> |
| | 1993 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 1994 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 1995 | | ''' </param> |
| | 1996 | | ''' <param name="retentionDays"> |
| | 1997 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 1998 | | ''' Only used when creating a new log. |
| | 1999 | | ''' </param> |
| | 2000 | | ''' <param name="writeInitEntry"> |
| | 2001 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2002 | | ''' </param> |
| | 2003 | | ''' <remarks> |
| | 2004 | | ''' <para> |
| | 2005 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2006 | | ''' </para> |
| | 2007 | | ''' <para> |
| | 2008 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2009 | | ''' </para> |
| | 2010 | | ''' </remarks> |
| 4 | 2011 | | Public Sub Log( |
| 4 | 2012 | | ByVal message As String, |
| 4 | 2013 | | ByVal maxKilobytes As Integer, |
| 4 | 2014 | | ByVal retentionDays As Integer, |
| 4 | 2015 | | ByVal writeInitEntry As Boolean) |
| | 2016 | |
|
| 8 | 2017 | | Log( |
| 8 | 2018 | | message, |
| 8 | 2019 | | EventLogEntryType.Information, |
| 8 | 2020 | | maxKilobytes, |
| 8 | 2021 | | retentionDays, |
| 8 | 2022 | | writeInitEntry) |
| | 2023 | |
|
| 8 | 2024 | | End Sub |
| | 2025 | |
|
| | 2026 | | ''' <summary> |
| | 2027 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 2028 | | ''' </summary> |
| | 2029 | | ''' <param name="message"> |
| | 2030 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2031 | | ''' |
| | 2032 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2033 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2034 | | ''' |
| | 2035 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2036 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2037 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2038 | | ''' </param> |
| | 2039 | | ''' <param name="eventType"> |
| | 2040 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2041 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2042 | | ''' </param> |
| | 2043 | | ''' <param name="maxKilobytes"> |
| | 2044 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 2045 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 2046 | | ''' </param> |
| | 2047 | | ''' <param name="retentionDays"> |
| | 2048 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 2049 | | ''' Only used when creating a new log. |
| | 2050 | | ''' </param> |
| | 2051 | | ''' <param name="writeInitEntry"> |
| | 2052 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2053 | | ''' </param> |
| | 2054 | | ''' <remarks> |
| | 2055 | | ''' <para> |
| | 2056 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2057 | | ''' </para> |
| | 2058 | | ''' <para> |
| | 2059 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2060 | | ''' </para> |
| | 2061 | | ''' </remarks> |
| 4 | 2062 | | Public Sub Log( |
| 4 | 2063 | | ByVal message As String, |
| 4 | 2064 | | ByVal eventType As EventLogEntryType, |
| 4 | 2065 | | ByVal maxKilobytes As Integer, |
| 4 | 2066 | | ByVal retentionDays As Integer, |
| 4 | 2067 | | ByVal writeInitEntry As Boolean) |
| | 2068 | |
|
| 8 | 2069 | | Log( |
| 8 | 2070 | | message, |
| 8 | 2071 | | eventType, |
| 8 | 2072 | | 0, |
| 8 | 2073 | | maxKilobytes, |
| 8 | 2074 | | retentionDays, |
| 8 | 2075 | | writeInitEntry) |
| | 2076 | |
|
| 8 | 2077 | | End Sub |
| | 2078 | |
|
| | 2079 | | ''' <summary> |
| | 2080 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 2081 | | ''' </summary> |
| | 2082 | | ''' <param name="message"> |
| | 2083 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2084 | | ''' |
| | 2085 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2086 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2087 | | ''' |
| | 2088 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2089 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2090 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2091 | | ''' </param> |
| | 2092 | | ''' <param name="eventType"> |
| | 2093 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2094 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2095 | | ''' </param> |
| | 2096 | | ''' <param name="eventID"> |
| | 2097 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 2098 | | ''' </param> |
| | 2099 | | ''' <param name="maxKilobytes"> |
| | 2100 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 2101 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 2102 | | ''' </param> |
| | 2103 | | ''' <param name="retentionDays"> |
| | 2104 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 2105 | | ''' Only used when creating a new log. |
| | 2106 | | ''' </param> |
| | 2107 | | ''' <param name="writeInitEntry"> |
| | 2108 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2109 | | ''' </param> |
| | 2110 | | ''' <remarks> |
| | 2111 | | ''' <para> |
| | 2112 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2113 | | ''' </para> |
| | 2114 | | ''' <para> |
| | 2115 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2116 | | ''' </para> |
| | 2117 | | ''' </remarks> |
| 4 | 2118 | | Public Sub Log( |
| 4 | 2119 | | ByVal message As String, |
| 4 | 2120 | | ByVal eventType As EventLogEntryType, |
| 4 | 2121 | | ByVal eventID As Integer, |
| 4 | 2122 | | ByVal maxKilobytes As Integer, |
| 4 | 2123 | | ByVal retentionDays As Integer, |
| 4 | 2124 | | ByVal writeInitEntry As Boolean) |
| | 2125 | |
|
| 8 | 2126 | | Log( |
| 8 | 2127 | | message, |
| 8 | 2128 | | eventType, |
| 8 | 2129 | | eventID, |
| 8 | 2130 | | 0, |
| 8 | 2131 | | maxKilobytes, |
| 8 | 2132 | | retentionDays, |
| 8 | 2133 | | writeInitEntry) |
| | 2134 | |
|
| 8 | 2135 | | End Sub |
| | 2136 | |
|
| | 2137 | | ''' <summary> |
| | 2138 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 2139 | | ''' </summary> |
| | 2140 | | ''' <param name="message"> |
| | 2141 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2142 | | ''' |
| | 2143 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2144 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2145 | | ''' |
| | 2146 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2147 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2148 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2149 | | ''' </param> |
| | 2150 | | ''' <param name="eventType"> |
| | 2151 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2152 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2153 | | ''' </param> |
| | 2154 | | ''' <param name="eventID"> |
| | 2155 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 2156 | | ''' </param> |
| | 2157 | | ''' <param name="category"> |
| | 2158 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 2159 | | ''' </param> |
| | 2160 | | ''' <param name="maxKilobytes"> |
| | 2161 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 2162 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 2163 | | ''' </param> |
| | 2164 | | ''' <param name="retentionDays"> |
| | 2165 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 2166 | | ''' Only used when creating a new log. |
| | 2167 | | ''' </param> |
| | 2168 | | ''' <param name="writeInitEntry"> |
| | 2169 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2170 | | ''' </param> |
| | 2171 | | ''' <remarks> |
| | 2172 | | ''' <para> |
| | 2173 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2174 | | ''' </para> |
| | 2175 | | ''' <para> |
| | 2176 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2177 | | ''' </para> |
| | 2178 | | ''' </remarks> |
| 4 | 2179 | | Public Sub Log( |
| 4 | 2180 | | ByVal message As String, |
| 4 | 2181 | | ByVal eventType As EventLogEntryType, |
| 4 | 2182 | | ByVal eventID As Integer, |
| 4 | 2183 | | ByVal category As Short, |
| 4 | 2184 | | ByVal maxKilobytes As Integer, |
| 4 | 2185 | | ByVal retentionDays As Integer, |
| 4 | 2186 | | ByVal writeInitEntry As Boolean) |
| | 2187 | |
|
| 8 | 2188 | | Log( |
| 8 | 2189 | | message, |
| 8 | 2190 | | eventType, |
| 8 | 2191 | | eventID, |
| 8 | 2192 | | category, |
| 8 | 2193 | | Nothing, |
| 8 | 2194 | | maxKilobytes, |
| 8 | 2195 | | retentionDays, |
| 8 | 2196 | | writeInitEntry) |
| | 2197 | |
|
| 8 | 2198 | | End Sub |
| | 2199 | |
|
| | 2200 | | ''' <summary> |
| | 2201 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 2202 | | ''' </summary> |
| | 2203 | | ''' <param name="message"> |
| | 2204 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2205 | | ''' |
| | 2206 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2207 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2208 | | ''' |
| | 2209 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2210 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2211 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2212 | | ''' </param> |
| | 2213 | | ''' <param name="eventType"> |
| | 2214 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2215 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2216 | | ''' </param> |
| | 2217 | | ''' <param name="eventID"> |
| | 2218 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 2219 | | ''' </param> |
| | 2220 | | ''' <param name="category"> |
| | 2221 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 2222 | | ''' </param> |
| | 2223 | | ''' <param name="rawData"> |
| | 2224 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 2225 | | ''' </param> |
| | 2226 | | ''' <param name="maxKilobytes"> |
| | 2227 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 2228 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 2229 | | ''' </param> |
| | 2230 | | ''' <param name="retentionDays"> |
| | 2231 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 2232 | | ''' Only used when creating a new log. |
| | 2233 | | ''' </param> |
| | 2234 | | ''' <param name="writeInitEntry"> |
| | 2235 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2236 | | ''' </param> |
| | 2237 | | ''' <remarks> |
| | 2238 | | ''' <para> |
| | 2239 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2240 | | ''' </para> |
| | 2241 | | ''' <para> |
| | 2242 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2243 | | ''' </para> |
| | 2244 | | ''' </remarks> |
| 4 | 2245 | | Public Sub Log( |
| 4 | 2246 | | ByVal message As String, |
| 4 | 2247 | | ByVal eventType As EventLogEntryType, |
| 4 | 2248 | | ByVal eventID As Integer, |
| 4 | 2249 | | ByVal category As Short, |
| 4 | 2250 | | ByVal rawData As Byte(), |
| 4 | 2251 | | ByVal maxKilobytes As Integer, |
| 4 | 2252 | | ByVal retentionDays As Integer, |
| 4 | 2253 | | ByVal writeInitEntry As Boolean) |
| | 2254 | |
|
| 8 | 2255 | | Log( |
| 8 | 2256 | | "", |
| 8 | 2257 | | message, |
| 8 | 2258 | | eventType, |
| 8 | 2259 | | eventID, |
| 8 | 2260 | | category, |
| 8 | 2261 | | rawData, |
| 8 | 2262 | | maxKilobytes, |
| 8 | 2263 | | retentionDays, |
| 8 | 2264 | | writeInitEntry) |
| | 2265 | |
|
| 8 | 2266 | | End Sub |
| | 2267 | |
|
| | 2268 | | ''' <summary> |
| | 2269 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 2270 | | ''' </summary> |
| | 2271 | | ''' <param name="sourceName"> |
| | 2272 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 2273 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 2274 | | ''' </param> |
| | 2275 | | ''' <param name="message"> |
| | 2276 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2277 | | ''' |
| | 2278 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2279 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2280 | | ''' |
| | 2281 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2282 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2283 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2284 | | ''' </param> |
| | 2285 | | ''' <param name="eventType"> |
| | 2286 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2287 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2288 | | ''' </param> |
| | 2289 | | ''' <param name="eventID"> |
| | 2290 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 2291 | | ''' </param> |
| | 2292 | | ''' <param name="category"> |
| | 2293 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 2294 | | ''' </param> |
| | 2295 | | ''' <param name="rawData"> |
| | 2296 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 2297 | | ''' </param> |
| | 2298 | | ''' <param name="maxKilobytes"> |
| | 2299 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 2300 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 2301 | | ''' </param> |
| | 2302 | | ''' <param name="retentionDays"> |
| | 2303 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 2304 | | ''' Only used when creating a new log. |
| | 2305 | | ''' </param> |
| | 2306 | | ''' <param name="writeInitEntry"> |
| | 2307 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2308 | | ''' </param> |
| | 2309 | | ''' <remarks> |
| | 2310 | | ''' <para> |
| | 2311 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2312 | | ''' </para> |
| | 2313 | | ''' <para> |
| | 2314 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2315 | | ''' </para> |
| | 2316 | | ''' </remarks> |
| 4 | 2317 | | Public Sub Log( |
| 4 | 2318 | | ByVal sourceName As String, |
| 4 | 2319 | | ByVal message As String, |
| 4 | 2320 | | ByVal eventType As EventLogEntryType, |
| 4 | 2321 | | ByVal eventID As Integer, |
| 4 | 2322 | | ByVal category As Short, |
| 4 | 2323 | | ByVal rawData As Byte(), |
| 4 | 2324 | | ByVal maxKilobytes As Integer, |
| 4 | 2325 | | ByVal retentionDays As Integer, |
| 4 | 2326 | | ByVal writeInitEntry As Boolean) |
| | 2327 | |
|
| 8 | 2328 | | Log( |
| 8 | 2329 | | "", |
| 8 | 2330 | | sourceName, |
| 8 | 2331 | | message, |
| 8 | 2332 | | eventType, |
| 8 | 2333 | | eventID, |
| 8 | 2334 | | category, |
| 8 | 2335 | | rawData, |
| 8 | 2336 | | maxKilobytes, |
| 8 | 2337 | | retentionDays, |
| 8 | 2338 | | writeInitEntry) |
| | 2339 | |
|
| 8 | 2340 | | End Sub |
| | 2341 | |
|
| | 2342 | | ''' <summary> |
| | 2343 | | ''' Writes an entry to the Windows Event Log using the provided parameters. |
| | 2344 | | ''' </summary> |
| | 2345 | | ''' <param name="logName"> |
| | 2346 | | ''' The name of the event log to write to (e.g., "Application", "System", or a custom log name). |
| | 2347 | | ''' If <c>null</c> or empty, "Application" is used by default. |
| | 2348 | | ''' </param> |
| | 2349 | | ''' <param name="sourceName"> |
| | 2350 | | ''' The source of the log entry. If <c>null</c> or empty, a default source is generated using the calling method's |
| | 2351 | | ''' namespace, class, and method name. If the source exceeds 254 characters, it is automatically truncated. |
| | 2352 | | ''' </param> |
| | 2353 | | ''' <param name="message"> |
| | 2354 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2355 | | ''' |
| | 2356 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2357 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2358 | | ''' |
| | 2359 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2360 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2361 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2362 | | ''' </param> |
| | 2363 | | ''' <param name="eventType"> |
| | 2364 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2365 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2366 | | ''' </param> |
| | 2367 | | ''' <param name="eventID"> |
| | 2368 | | ''' The numeric event identifier for the log entry. This is application-defined and may be used to group similar eve |
| | 2369 | | ''' </param> |
| | 2370 | | ''' <param name="category"> |
| | 2371 | | ''' The category for the event, if applicable. This is typically used in categorized event views. |
| | 2372 | | ''' </param> |
| | 2373 | | ''' <param name="rawData"> |
| | 2374 | | ''' Optional binary data to include with the log entry. Can be <c>null</c> if not used. |
| | 2375 | | ''' </param> |
| | 2376 | | ''' <param name="maxKilobytes"> |
| | 2377 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 2378 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 2379 | | ''' </param> |
| | 2380 | | ''' <param name="retentionDays"> |
| | 2381 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 2382 | | ''' Only used when creating a new log. |
| | 2383 | | ''' </param> |
| | 2384 | | ''' <param name="writeInitEntry"> |
| | 2385 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 2386 | | ''' </param> |
| | 2387 | | ''' <remarks> |
| | 2388 | | ''' <para> |
| | 2389 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2390 | | ''' </para> |
| | 2391 | | ''' <para> |
| | 2392 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2393 | | ''' </para> |
| | 2394 | | ''' </remarks> |
| 4 | 2395 | | Public Sub Log( |
| 4 | 2396 | | ByVal logName As String, |
| 4 | 2397 | | ByVal sourceName As String, |
| 4 | 2398 | | ByVal message As String, |
| 4 | 2399 | | ByVal eventType As EventLogEntryType, |
| 4 | 2400 | | ByVal eventID As Integer, |
| 4 | 2401 | | ByVal category As Short, |
| 4 | 2402 | | ByVal rawData As Byte(), |
| 4 | 2403 | | ByVal maxKilobytes As Integer, |
| 4 | 2404 | | ByVal retentionDays As Integer, |
| 4 | 2405 | | ByVal writeInitEntry As Boolean) |
| | 2406 | |
|
| 8 | 2407 | | Log( |
| 8 | 2408 | | "", |
| 8 | 2409 | | logName, |
| 8 | 2410 | | sourceName, |
| 8 | 2411 | | message, |
| 8 | 2412 | | eventType, |
| 8 | 2413 | | eventID, |
| 8 | 2414 | | category, |
| 8 | 2415 | | rawData, |
| 8 | 2416 | | maxKilobytes, |
| 8 | 2417 | | retentionDays, |
| 8 | 2418 | | writeInitEntry) |
| | 2419 | |
|
| 8 | 2420 | | End Sub |
| | 2421 | |
|
| | 2422 | | ''' <summary> |
| | 2423 | | ''' Writes an entry (or entries) to the Windows Event Log using the specified parameters. |
| | 2424 | | ''' </summary> |
| | 2425 | | ''' <param name="_machineName"> |
| | 2426 | | ''' The name of the machine where the event log resides. Use <c>"."</c> for the local machine. |
| | 2427 | | ''' If <c>null</c> or empty, the local machine is used by default, or the value of the <see cref="MachineName"/> pro |
| | 2428 | | ''' </param> |
| | 2429 | | ''' <param name="_logName"> |
| | 2430 | | ''' The name of the event log (e.g., <c>"Application"</c>, <c>"System"</c>, or a custom log name). |
| | 2431 | | ''' If <c>null</c> or empty, the value of the <see cref="LogName"/> property is used. |
| | 2432 | | ''' </param> |
| | 2433 | | ''' <param name="sourceName"> |
| | 2434 | | ''' The source name for the event entry. If <c>null</c> or empty, a source is auto-generated from the calling method |
| | 2435 | | ''' If the resulting name exceeds 254 characters, it will be truncated. |
| | 2436 | | ''' </param> |
| | 2437 | | ''' <param name="message"> |
| | 2438 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2439 | | ''' |
| | 2440 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2441 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2442 | | ''' |
| | 2443 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2444 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2445 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2446 | | ''' </param> |
| | 2447 | | ''' <param name="eventType"> |
| | 2448 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2449 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2450 | | ''' </param> |
| | 2451 | | ''' <param name="eventID"> |
| | 2452 | | ''' The numeric event identifier. Application-defined and useful for grouping related events. |
| | 2453 | | ''' </param> |
| | 2454 | | ''' <param name="category"> |
| | 2455 | | ''' The category ID for the event. Use 0 if not applicable. |
| | 2456 | | ''' </param> |
| | 2457 | | ''' <param name="rawData"> |
| | 2458 | | ''' Optional binary data to associate with the event. Can be <c>null</c>. |
| | 2459 | | ''' </param> |
| | 2460 | | ''' <param name="maxKilobytes"> |
| | 2461 | | ''' The maximum size of the event log in kilobytes. Only applies when creating a new log. Range: 64 KB – 4 GB. |
| | 2462 | | ''' </param> |
| | 2463 | | ''' <param name="retentionDays"> |
| | 2464 | | ''' The number of days entries should be retained. 0 means entries are kept indefinitely. |
| | 2465 | | ''' Applies only when creating a new log. |
| | 2466 | | ''' </param> |
| | 2467 | | ''' <param name="writeInitEntry"> |
| | 2468 | | ''' Whether to write an initialization entry when a new log is created. |
| | 2469 | | ''' </param> |
| | 2470 | | ''' <remarks> |
| | 2471 | | ''' <para> |
| | 2472 | | ''' If the specified event log or source does not exist, they are created automatically using the provided parameter |
| | 2473 | | ''' </para> |
| | 2474 | | ''' <para> |
| | 2475 | | ''' This method handles safe formatting, validation, and optional message splitting to avoid truncation of diagnosti |
| | 2476 | | ''' </para> |
| | 2477 | | ''' </remarks> |
| 104 | 2478 | | Public Sub Log( |
| 104 | 2479 | | ByVal _machineName As String, |
| 104 | 2480 | | ByVal _logName As String, |
| 104 | 2481 | | ByVal sourceName As String, |
| 104 | 2482 | | ByVal message As String, |
| 104 | 2483 | | ByVal eventType As EventLogEntryType, |
| 104 | 2484 | | ByVal eventID As Integer, |
| 104 | 2485 | | ByVal category As Short, |
| 104 | 2486 | | ByVal rawData As Byte(), |
| 104 | 2487 | | ByVal maxKilobytes As Integer, |
| 104 | 2488 | | ByVal retentionDays As Integer, |
| 104 | 2489 | | ByVal writeInitEntry As Boolean) |
| | 2490 | |
|
| 208 | 2491 | | Initialize() |
| | 2492 | |
|
| 208 | 2493 | | Dim defaultLog As String = If(String.IsNullOrEmpty(_logName), LogName, _logName.Trim()) |
| 208 | 2494 | | Dim defaultSource As String = Source(sourceName) |
| 208 | 2495 | | Dim defaultMachine As String = NormalizeMachineName(_machineName) |
| | 2496 | |
|
| 208 | 2497 | | If Not _writer.Exists(defaultLog, defaultMachine) OrElse Not _writer.SourceExists(defaultSource, defaultMachine) |
| 184 | 2498 | | _writer.CreateEventSource(defaultSource, defaultLog, _machineName) |
| 196 | 2499 | | End If |
| | 2500 | |
|
| 208 | 2501 | | Dim finalEventType As EventLogEntryType = NormalizeEventType(eventType) |
| | 2502 | |
|
| 208 | 2503 | | If AllowMultiEntryMessages AndAlso message.Length > 32766 Then |
| 8 | 2504 | | For Each chunk As String In SplitMessageIntoPages(defaultSource, message) |
| 16 | 2505 | | _writer.WriteEntry(defaultMachine, |
| 16 | 2506 | | defaultLog, |
| 16 | 2507 | | defaultSource, |
| 16 | 2508 | | chunk, |
| 16 | 2509 | | finalEventType, |
| 16 | 2510 | | eventID, |
| 16 | 2511 | | category, |
| 16 | 2512 | | rawData, |
| 16 | 2513 | | maxKilobytes, |
| 16 | 2514 | | retentionDays, |
| 16 | 2515 | | writeInitEntry) |
| 8 | 2516 | | Next |
| 100 | 2517 | | Else |
| 200 | 2518 | | _writer.WriteEntry(defaultMachine, |
| 200 | 2519 | | defaultLog, |
| 200 | 2520 | | defaultSource, |
| 200 | 2521 | | NormalizeMessage(defaultSource, message), |
| 200 | 2522 | | finalEventType, |
| 200 | 2523 | | eventID, |
| 200 | 2524 | | category, |
| 200 | 2525 | | rawData, |
| 200 | 2526 | | maxKilobytes, |
| 200 | 2527 | | retentionDays, |
| 200 | 2528 | | writeInitEntry) |
| 104 | 2529 | | End If |
| | 2530 | |
|
| 208 | 2531 | | End Sub |
| | 2532 | |
|
| | 2533 | | #End Region |
| | 2534 | |
|
| | 2535 | | #Region " Log Extension Methods ^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 2536 | |
|
| | 2537 | | ''' <summary> |
| | 2538 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2539 | | ''' </summary> |
| | 2540 | | ''' <param name="eventLog"> |
| | 2541 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2542 | | ''' with a valid log name and source. |
| | 2543 | | ''' </param> |
| | 2544 | | ''' <param name="message"> |
| | 2545 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2546 | | ''' |
| | 2547 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2548 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2549 | | ''' |
| | 2550 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2551 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2552 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2553 | | ''' </param> |
| | 2554 | | ''' <remarks> |
| | 2555 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2556 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2557 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2558 | | ''' </remarks> |
| | 2559 | | <Extension> |
| 4 | 2560 | | Public Sub LogEntry( |
| 4 | 2561 | | ByVal eventLog As EventLog, |
| 4 | 2562 | | ByVal message As String) |
| | 2563 | |
|
| 8 | 2564 | | LogEntry(eventLog, |
| 8 | 2565 | | message, |
| 8 | 2566 | | EventLogEntryType.Information) |
| | 2567 | |
|
| 8 | 2568 | | End Sub |
| | 2569 | |
|
| | 2570 | | ''' <summary> |
| | 2571 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2572 | | ''' </summary> |
| | 2573 | | ''' <param name="eventLog"> |
| | 2574 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2575 | | ''' with a valid log name and source. |
| | 2576 | | ''' </param> |
| | 2577 | | ''' <param name="message"> |
| | 2578 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2579 | | ''' |
| | 2580 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2581 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2582 | | ''' |
| | 2583 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2584 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2585 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2586 | | ''' </param> |
| | 2587 | | ''' <param name="eventType"> |
| | 2588 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2589 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2590 | | ''' </param> |
| | 2591 | | ''' <remarks> |
| | 2592 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2593 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2594 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2595 | | ''' </remarks> |
| | 2596 | | <Extension> |
| 4 | 2597 | | Public Sub LogEntry( |
| 4 | 2598 | | ByVal eventLog As EventLog, |
| 4 | 2599 | | ByVal message As String, |
| 4 | 2600 | | ByVal eventType As EventLogEntryType) |
| | 2601 | |
|
| 8 | 2602 | | LogEntry(eventLog, |
| 8 | 2603 | | message, |
| 8 | 2604 | | eventType, |
| 8 | 2605 | | 0) |
| | 2606 | |
|
| 8 | 2607 | | End Sub |
| | 2608 | |
|
| | 2609 | | ''' <summary> |
| | 2610 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2611 | | ''' </summary> |
| | 2612 | | ''' <param name="eventLog"> |
| | 2613 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2614 | | ''' with a valid log name and source. |
| | 2615 | | ''' </param> |
| | 2616 | | ''' <param name="message"> |
| | 2617 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2618 | | ''' |
| | 2619 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2620 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2621 | | ''' |
| | 2622 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2623 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2624 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2625 | | ''' </param> |
| | 2626 | | ''' <param name="eventID"> |
| | 2627 | | ''' A numeric identifier for the event. This value is application-defined and can be used for categorizing |
| | 2628 | | ''' or filtering related log entries. |
| | 2629 | | ''' </param> |
| | 2630 | | ''' <remarks> |
| | 2631 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2632 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2633 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2634 | | ''' </remarks> |
| | 2635 | | <Extension> |
| 4 | 2636 | | Public Sub LogEntry( |
| 4 | 2637 | | ByVal eventLog As EventLog, |
| 4 | 2638 | | ByVal message As String, |
| 4 | 2639 | | ByVal eventID As Integer) |
| | 2640 | |
|
| 8 | 2641 | | LogEntry(eventLog, |
| 8 | 2642 | | message, |
| 8 | 2643 | | EventLogEntryType.Information, |
| 8 | 2644 | | eventID) |
| | 2645 | |
|
| 8 | 2646 | | End Sub |
| | 2647 | |
|
| | 2648 | | ''' <summary> |
| | 2649 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2650 | | ''' </summary> |
| | 2651 | | ''' <param name="eventLog"> |
| | 2652 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2653 | | ''' with a valid log name and source. |
| | 2654 | | ''' </param> |
| | 2655 | | ''' <param name="message"> |
| | 2656 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2657 | | ''' |
| | 2658 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2659 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2660 | | ''' |
| | 2661 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2662 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2663 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2664 | | ''' </param> |
| | 2665 | | ''' <param name="category"> |
| | 2666 | | ''' A numeric category for the event. This is typically used in categorized views of the Event Log. |
| | 2667 | | ''' Use 0 if no category is needed. |
| | 2668 | | ''' </param> |
| | 2669 | | ''' <remarks> |
| | 2670 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2671 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2672 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2673 | | ''' </remarks> |
| | 2674 | | <Extension> |
| 4 | 2675 | | Public Sub LogEntry( |
| 4 | 2676 | | ByVal eventLog As EventLog, |
| 4 | 2677 | | ByVal message As String, |
| 4 | 2678 | | ByVal category As Short) |
| | 2679 | |
|
| 8 | 2680 | | LogEntry(eventLog, |
| 8 | 2681 | | message, |
| 8 | 2682 | | EventLogEntryType.Information, |
| 8 | 2683 | | category) |
| | 2684 | |
|
| 8 | 2685 | | End Sub |
| | 2686 | |
|
| | 2687 | | ''' <summary> |
| | 2688 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2689 | | ''' </summary> |
| | 2690 | | ''' <param name="eventLog"> |
| | 2691 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2692 | | ''' with a valid log name and source. |
| | 2693 | | ''' </param> |
| | 2694 | | ''' <param name="message"> |
| | 2695 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2696 | | ''' |
| | 2697 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2698 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2699 | | ''' |
| | 2700 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2701 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2702 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2703 | | ''' </param> |
| | 2704 | | ''' <param name="eventType"> |
| | 2705 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2706 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2707 | | ''' </param> |
| | 2708 | | ''' <param name="eventID"> |
| | 2709 | | ''' A numeric identifier for the event. This value is application-defined and can be used for categorizing |
| | 2710 | | ''' or filtering related log entries. |
| | 2711 | | ''' </param> |
| | 2712 | | ''' <remarks> |
| | 2713 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2714 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2715 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2716 | | ''' </remarks> |
| | 2717 | | <Extension> |
| 8 | 2718 | | Public Sub LogEntry( |
| 8 | 2719 | | ByVal eventLog As EventLog, |
| 8 | 2720 | | ByVal message As String, |
| 8 | 2721 | | ByVal eventType As EventLogEntryType, |
| 8 | 2722 | | ByVal eventID As Integer) |
| | 2723 | |
|
| 16 | 2724 | | LogEntry(eventLog, |
| 16 | 2725 | | message, |
| 16 | 2726 | | eventType, |
| 16 | 2727 | | eventID, |
| 16 | 2728 | | 0) |
| | 2729 | |
|
| 16 | 2730 | | End Sub |
| | 2731 | |
|
| | 2732 | | ''' <summary> |
| | 2733 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2734 | | ''' </summary> |
| | 2735 | | ''' <param name="eventLog"> |
| | 2736 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2737 | | ''' with a valid log name and source. |
| | 2738 | | ''' </param> |
| | 2739 | | ''' <param name="message"> |
| | 2740 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2741 | | ''' |
| | 2742 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2743 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2744 | | ''' |
| | 2745 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2746 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2747 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2748 | | ''' </param> |
| | 2749 | | ''' <param name="eventType"> |
| | 2750 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2751 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2752 | | ''' </param> |
| | 2753 | | ''' <param name="category"> |
| | 2754 | | ''' A numeric category for the event. This is typically used in categorized views of the Event Log. |
| | 2755 | | ''' Use 0 if no category is needed. |
| | 2756 | | ''' </param> |
| | 2757 | | ''' <remarks> |
| | 2758 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2759 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2760 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2761 | | ''' </remarks> |
| | 2762 | | <Extension> |
| 4 | 2763 | | Public Sub LogEntry( |
| 4 | 2764 | | ByVal eventLog As EventLog, |
| 4 | 2765 | | ByVal message As String, |
| 4 | 2766 | | ByVal eventType As EventLogEntryType, |
| 4 | 2767 | | ByVal category As Short) |
| | 2768 | |
|
| 8 | 2769 | | LogEntry(eventLog, |
| 8 | 2770 | | message, |
| 8 | 2771 | | eventType, |
| 8 | 2772 | | 0, |
| 8 | 2773 | | category) |
| | 2774 | |
|
| 8 | 2775 | | End Sub |
| | 2776 | |
|
| | 2777 | | ''' <summary> |
| | 2778 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2779 | | ''' </summary> |
| | 2780 | | ''' <param name="eventLog"> |
| | 2781 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2782 | | ''' with a valid log name and source. |
| | 2783 | | ''' </param> |
| | 2784 | | ''' <param name="message"> |
| | 2785 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2786 | | ''' |
| | 2787 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2788 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2789 | | ''' |
| | 2790 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2791 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2792 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2793 | | ''' </param> |
| | 2794 | | ''' <param name="eventType"> |
| | 2795 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2796 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2797 | | ''' </param> |
| | 2798 | | ''' <param name="eventID"> |
| | 2799 | | ''' A numeric identifier for the event. This value is application-defined and can be used for categorizing |
| | 2800 | | ''' or filtering related log entries. |
| | 2801 | | ''' </param> |
| | 2802 | | ''' <param name="category"> |
| | 2803 | | ''' A numeric category for the event. This is typically used in categorized views of the Event Log. |
| | 2804 | | ''' Use 0 if no category is needed. |
| | 2805 | | ''' </param> |
| | 2806 | | ''' <remarks> |
| | 2807 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2808 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2809 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2810 | | ''' </remarks> |
| | 2811 | | <Extension> |
| 12 | 2812 | | Public Sub LogEntry( |
| 12 | 2813 | | ByVal eventLog As EventLog, |
| 12 | 2814 | | ByVal message As String, |
| 12 | 2815 | | ByVal eventType As EventLogEntryType, |
| 12 | 2816 | | ByVal eventID As Integer, |
| 12 | 2817 | | ByVal category As Short) |
| | 2818 | |
|
| 24 | 2819 | | LogEntry(eventLog, |
| 24 | 2820 | | message, |
| 24 | 2821 | | eventType, |
| 24 | 2822 | | eventID, |
| 24 | 2823 | | category, |
| 24 | 2824 | | Nothing) |
| | 2825 | |
|
| 24 | 2826 | | End Sub |
| | 2827 | |
|
| | 2828 | | ''' <summary> |
| | 2829 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2830 | | ''' </summary> |
| | 2831 | | ''' <param name="eventLog"> |
| | 2832 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2833 | | ''' with a valid log name and source. |
| | 2834 | | ''' </param> |
| | 2835 | | ''' <param name="message"> |
| | 2836 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2837 | | ''' |
| | 2838 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2839 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2840 | | ''' |
| | 2841 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2842 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2843 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2844 | | ''' </param> |
| | 2845 | | ''' <param name="rawData"> |
| | 2846 | | ''' Optional binary data to associate with the log entry. This can be <c>null</c> if unused. |
| | 2847 | | ''' </param> |
| | 2848 | | ''' <remarks> |
| | 2849 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2850 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2851 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2852 | | ''' </remarks> |
| | 2853 | | <Extension> |
| 8 | 2854 | | Public Sub LogEntry( |
| 8 | 2855 | | ByVal eventLog As EventLog, |
| 8 | 2856 | | ByVal message As String, |
| 8 | 2857 | | ByVal rawData As Byte()) |
| | 2858 | |
|
| 16 | 2859 | | LogEntry(eventLog, |
| 16 | 2860 | | message, |
| 16 | 2861 | | EventLogEntryType.Information, |
| 16 | 2862 | | rawData) |
| | 2863 | |
|
| 16 | 2864 | | End Sub |
| | 2865 | |
|
| | 2866 | | ''' <summary> |
| | 2867 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2868 | | ''' </summary> |
| | 2869 | | ''' <param name="eventLog"> |
| | 2870 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2871 | | ''' with a valid log name and source. |
| | 2872 | | ''' </param> |
| | 2873 | | ''' <param name="message"> |
| | 2874 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2875 | | ''' |
| | 2876 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2877 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2878 | | ''' |
| | 2879 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2880 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2881 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2882 | | ''' </param> |
| | 2883 | | ''' <param name="eventType"> |
| | 2884 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2885 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2886 | | ''' </param> |
| | 2887 | | ''' <param name="rawData"> |
| | 2888 | | ''' Optional binary data to associate with the log entry. This can be <c>null</c> if unused. |
| | 2889 | | ''' </param> |
| | 2890 | | ''' <remarks> |
| | 2891 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2892 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2893 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2894 | | ''' </remarks> |
| | 2895 | | <Extension> |
| 8 | 2896 | | Public Sub LogEntry( |
| 8 | 2897 | | ByVal eventLog As EventLog, |
| 8 | 2898 | | ByVal message As String, |
| 8 | 2899 | | ByVal eventType As EventLogEntryType, |
| 8 | 2900 | | ByVal rawData As Byte()) |
| | 2901 | |
|
| 16 | 2902 | | LogEntry(eventLog, |
| 16 | 2903 | | message, |
| 16 | 2904 | | eventType, |
| 16 | 2905 | | 0, |
| 16 | 2906 | | rawData) |
| | 2907 | |
|
| 16 | 2908 | | End Sub |
| | 2909 | |
|
| | 2910 | | ''' <summary> |
| | 2911 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2912 | | ''' </summary> |
| | 2913 | | ''' <param name="eventLog"> |
| | 2914 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2915 | | ''' with a valid log name and source. |
| | 2916 | | ''' </param> |
| | 2917 | | ''' <param name="message"> |
| | 2918 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2919 | | ''' |
| | 2920 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2921 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2922 | | ''' |
| | 2923 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2924 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2925 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2926 | | ''' </param> |
| | 2927 | | ''' <param name="eventType"> |
| | 2928 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2929 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2930 | | ''' </param> |
| | 2931 | | ''' <param name="eventID"> |
| | 2932 | | ''' A numeric identifier for the event. This value is application-defined and can be used for categorizing |
| | 2933 | | ''' or filtering related log entries. |
| | 2934 | | ''' </param> |
| | 2935 | | ''' <param name="rawData"> |
| | 2936 | | ''' Optional binary data to associate with the log entry. This can be <c>null</c> if unused. |
| | 2937 | | ''' </param> |
| | 2938 | | ''' <remarks> |
| | 2939 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2940 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2941 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2942 | | ''' </remarks> |
| | 2943 | | <Extension> |
| 8 | 2944 | | Public Sub LogEntry( |
| 8 | 2945 | | ByVal eventLog As EventLog, |
| 8 | 2946 | | ByVal message As String, |
| 8 | 2947 | | ByVal eventType As EventLogEntryType, |
| 8 | 2948 | | ByVal eventID As Integer, |
| 8 | 2949 | | ByVal rawData As Byte()) |
| | 2950 | |
|
| 16 | 2951 | | LogEntry(eventLog, |
| 16 | 2952 | | message, |
| 16 | 2953 | | eventType, |
| 16 | 2954 | | eventID, |
| 16 | 2955 | | 0, |
| 16 | 2956 | | rawData) |
| | 2957 | |
|
| 16 | 2958 | | End Sub |
| | 2959 | |
|
| | 2960 | | ''' <summary> |
| | 2961 | | ''' Writes a log entry to the specified <see cref="EventLog"/> with the given parameters. |
| | 2962 | | ''' </summary> |
| | 2963 | | ''' <param name="eventLog"> |
| | 2964 | | ''' The <see cref="EventLog"/> instance to which the entry will be written. This must be properly initialized |
| | 2965 | | ''' with a valid log name and source. |
| | 2966 | | ''' </param> |
| | 2967 | | ''' <param name="message"> |
| | 2968 | | ''' The message to log. If <c>null</c> or empty, a default message is used. |
| | 2969 | | ''' |
| | 2970 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>false</c> (default), messages longer than 32,766 characters are t |
| | 2971 | | ''' and suffixed with the <see cref="TruncationMarker"/> (e.g., <c>"... [TRUNCATED]"</c>). |
| | 2972 | | ''' |
| | 2973 | | ''' If <see cref="AllowMultiEntryMessages"/> is <c>true</c>, long messages are split into multiple event entries, |
| | 2974 | | ''' each prefixed with part information (e.g., <c>[Part 1/3]</c>) and intermediate entries are suffixed with |
| | 2975 | | ''' the <see cref="ContinuationMarker"/> (e.g., <c>" ..."</c>) to indicate continuation. |
| | 2976 | | ''' </param> |
| | 2977 | | ''' <param name="eventType"> |
| | 2978 | | ''' The type of event. Valid values are <see cref="EventLogEntryType.Error"/>, <see cref="EventLogEntryType.Warning" |
| | 2979 | | ''' <see cref="EventLogEntryType.Information"/>. If invalid, <c>Information</c> is used. |
| | 2980 | | ''' </param> |
| | 2981 | | ''' <param name="eventID"> |
| | 2982 | | ''' A numeric identifier for the event. This value is application-defined and can be used for categorizing |
| | 2983 | | ''' or filtering related log entries. |
| | 2984 | | ''' </param> |
| | 2985 | | ''' <param name="category"> |
| | 2986 | | ''' A numeric category for the event. This is typically used in categorized views of the Event Log. |
| | 2987 | | ''' Use 0 if no category is needed. |
| | 2988 | | ''' </param> |
| | 2989 | | ''' <param name="rawData"> |
| | 2990 | | ''' Optional binary data to associate with the log entry. This can be <c>null</c> if unused. |
| | 2991 | | ''' </param> |
| | 2992 | | ''' <remarks> |
| | 2993 | | ''' This method uses configured or default values for formatting and fallbacks. The message is normalized |
| | 2994 | | ''' and validated prior to writing. If you are using a test environment, an alternate writer can be configured |
| | 2995 | | ''' to intercept and test log output without writing to the system Event Log. |
| | 2996 | | ''' </remarks> |
| | 2997 | | <Extension> |
| 24 | 2998 | | Public Sub LogEntry( |
| 24 | 2999 | | ByVal eventLog As EventLog, |
| 24 | 3000 | | ByVal message As String, |
| 24 | 3001 | | ByVal eventType As EventLogEntryType, |
| 24 | 3002 | | ByVal eventID As Integer, |
| 24 | 3003 | | ByVal category As Short, |
| 24 | 3004 | | ByVal rawData As Byte()) |
| | 3005 | |
|
| 48 | 3006 | | Initialize() ' By the time we get here, this should already be done, but just in case. |
| | 3007 | |
|
| 48 | 3008 | | Dim defaultSource As String = Source(eventLog.Source) |
| 48 | 3009 | | Dim finalEventType As EventLogEntryType = NormalizeEventType(eventType) |
| | 3010 | |
|
| 48 | 3011 | | If AllowMultiEntryMessages AndAlso message.Length > 32766 Then |
| 8 | 3012 | | For Each chunk As String In SplitMessageIntoPages(defaultSource, message) |
| 16 | 3013 | | _writer.WriteEntry(eventLog, |
| 16 | 3014 | | chunk, |
| 16 | 3015 | | finalEventType, |
| 16 | 3016 | | eventID, |
| 16 | 3017 | | category, |
| 16 | 3018 | | rawData) |
| 8 | 3019 | | Next |
| 20 | 3020 | | Else |
| 40 | 3021 | | _writer.WriteEntry(eventLog, |
| 40 | 3022 | | NormalizeMessage(eventLog.Source, message), |
| 40 | 3023 | | NormalizeEventType(eventType), |
| 40 | 3024 | | eventID, |
| 40 | 3025 | | category, |
| 40 | 3026 | | rawData) |
| 24 | 3027 | | End If |
| | 3028 | |
|
| 48 | 3029 | | End Sub |
| | 3030 | |
|
| | 3031 | | #End Region |
| | 3032 | |
|
| | 3033 | | #Region " Support Functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 3034 | |
|
| | 3035 | | ''' <summary> |
| | 3036 | | ''' Returns a default event source name. If none is provided, this attempts to determine the calling |
| | 3037 | | ''' method's fully qualified name as the source. |
| | 3038 | | ''' </summary> |
| | 3039 | | ''' <param name="_sourceName">Optional. A specific source name to use. If null or empty, the calling method will be |
| | 3040 | | ''' <returns>A valid event source name derived from the input or calling method.</returns> |
| 264 | 3041 | | Public Function Source( |
| 264 | 3042 | | Optional ByVal _sourceName As String = Nothing) As String |
| | 3043 | |
|
| | 3044 | | ' Final fallback if nothing else is available |
| 528 | 3045 | | Dim strReturn As String = "SmartEventLogger" |
| | 3046 | |
|
| 528 | 3047 | | If String.IsNullOrEmpty(_sourceName) Then |
| 136 | 3048 | | If Not String.IsNullOrEmpty(SourceName) Then |
| 24 | 3049 | | strReturn = SourceName |
| 56 | 3050 | | Else |
| | 3051 | | ' Try to get the calling assembly (e.g., the one calling your library) |
| 112 | 3052 | | Dim thisAssembly As Assembly = Assembly.GetExecutingAssembly() |
| | 3053 | |
|
| 112 | 3054 | | Dim stackTrace As New StackTrace() |
| 112 | 3055 | | For i As Integer = 1 To stackTrace.FrameCount - 1 |
| 796 | 3056 | | Dim frame As StackFrame = stackTrace.GetFrame(i) |
| 796 | 3057 | | Dim method As MethodBase = frame.GetMethod() |
| 796 | 3058 | | Dim type As Type = method.DeclaringType |
| 796 | 3059 | | If type.Assembly IsNot thisAssembly Then |
| 112 | 3060 | | strReturn = $"{type.FullName}.{method.Name}" |
| 112 | 3061 | | Exit For |
| 342 | 3062 | | End If |
| 684 | 3063 | | Next |
| 80 | 3064 | | End If |
| 196 | 3065 | | Else |
| 392 | 3066 | | strReturn = _sourceName.Trim() |
| 264 | 3067 | | End If |
| | 3068 | |
|
| | 3069 | | ' Ensure the source name does not exceed the maximum length allowed by the Windows Event Log system |
| 528 | 3070 | | Return MaxSource(strReturn) |
| | 3071 | |
|
| 528 | 3072 | | End Function |
| | 3073 | |
|
| | 3074 | | ''' <summary> |
| | 3075 | | ''' Attempts to determine a default source name for the given event log by inspecting the registry. |
| | 3076 | | ''' </summary> |
| | 3077 | | ''' <param name="log">The name of the event log (e.g., "Application", "System").</param> |
| | 3078 | | ''' <returns>The name of a registered event source, or an empty string if none are found.</returns> |
| 4 | 3079 | | Public Function DefaultSource( |
| 4 | 3080 | | ByVal log As String) As String |
| | 3081 | |
|
| 8 | 3082 | | Initialize() |
| | 3083 | |
|
| 8 | 3084 | | Return DefaultSource(log, MachineName) |
| | 3085 | |
|
| 8 | 3086 | | End Function |
| | 3087 | |
|
| | 3088 | | ''' <summary> |
| | 3089 | | ''' Attempts to determine a default source name for the given event log by inspecting the registry. |
| | 3090 | | ''' </summary> |
| | 3091 | | ''' <param name="logName">The name of the event log (e.g., "Application", "System").</param> |
| | 3092 | | ''' <param name="machineName">The target machine name, or "." for the local machine.</param> |
| | 3093 | | ''' <returns>The name of a registered event source, or an empty string if none are found.</returns> |
| 4 | 3094 | | Public Function DefaultSource( |
| 4 | 3095 | | ByVal logName As String, |
| 4 | 3096 | | ByVal machineName As String) As String |
| | 3097 | |
|
| 8 | 3098 | | Return _registryReader.GetDefaultEventLogSource(logName, machineName) |
| | 3099 | |
|
| 8 | 3100 | | End Function |
| | 3101 | |
|
| | 3102 | | ''' <summary> |
| | 3103 | | ''' Truncates the source name to meet the maximum length allowed by the Windows Event Log system. |
| | 3104 | | ''' </summary> |
| | 3105 | | ''' <param name="sourceName">The original source name.</param> |
| | 3106 | | ''' <returns>A source name no longer than 211 characters.</returns> |
| | 3107 | | ''' <remarks> |
| | 3108 | | ''' If the input is null or empty, the method will derive a source name using the calling method. |
| | 3109 | | ''' </remarks> |
| 300 | 3110 | | Public Function MaxSource( |
| 300 | 3111 | | ByVal sourceName As String) As String |
| | 3112 | |
|
| 600 | 3113 | | If String.IsNullOrEmpty(sourceName) Then |
| 16 | 3114 | | sourceName = Source() |
| 308 | 3115 | | End If |
| | 3116 | |
|
| 600 | 3117 | | Return sourceName.Substring(0, If(sourceName.Length > 211, 211, sourceName.Length)) |
| | 3118 | |
|
| 600 | 3119 | | End Function |
| | 3120 | |
|
| | 3121 | | ''' <summary> |
| | 3122 | | ''' Checks whether a specific source is registered to a specific event log on the specified machine. |
| | 3123 | | ''' </summary> |
| | 3124 | | ''' <param name="sourceName">The name of the event source.</param> |
| | 3125 | | ''' <param name="logName">The name of the event log (e.g., "Application").</param> |
| | 3126 | | ''' <param name="machineName">The target machine name, or "." for the local machine.</param> |
| | 3127 | | ''' <returns><c>True</c> if the source is registered; otherwise, <c>False</c>.</returns> |
| 4 | 3128 | | Public Function IsSourceRegisteredToLog( |
| 4 | 3129 | | ByVal sourceName As String, |
| 4 | 3130 | | ByVal logName As String, |
| 4 | 3131 | | ByVal machineName As String) As Boolean |
| | 3132 | |
|
| 8 | 3133 | | Dim registryPath As String = $"SYSTEM\CurrentControlSet\Services\EventLog\{logName}\{sourceName}" |
| | 3134 | |
|
| 8 | 3135 | | Return _registryReader.SubKeyExists(RegistryHive.LocalMachine, machineName, registryPath) |
| | 3136 | |
|
| 8 | 3137 | | End Function |
| | 3138 | |
|
| | 3139 | | ''' <summary> |
| | 3140 | | ''' Checks if the current user has read access to the registry key for a specific event log source. |
| | 3141 | | ''' </summary> |
| | 3142 | | ''' <param name="sourceName">The name of the event source.</param> |
| | 3143 | | ''' <param name="logName">The name of the event log.</param> |
| | 3144 | | ''' <param name="machineName">The machine to check, or "." for local machine.</param> |
| | 3145 | | ''' <returns><c>True</c> if the registry key can be read; otherwise, <c>False</c>.</returns> |
| 4 | 3146 | | Public Function CanReadRegistryForLogAndSource( |
| 4 | 3147 | | ByVal sourceName As String, |
| 4 | 3148 | | ByVal logName As String, |
| 4 | 3149 | | ByVal machineName As String) As Boolean |
| | 3150 | |
|
| 8 | 3151 | | Dim registryPath As String = $"SYSTEM\CurrentControlSet\Services\EventLog\{logName}\{sourceName}" |
| | 3152 | |
|
| 8 | 3153 | | Return _registryReader.HasRegistryAccess(RegistryHive.LocalMachine, machineName, registryPath, False) |
| | 3154 | |
|
| 8 | 3155 | | End Function |
| | 3156 | |
|
| | 3157 | | ''' <summary> |
| | 3158 | | ''' Determines if the current user has access (read or write) to the registry key for a given event log. |
| | 3159 | | ''' </summary> |
| | 3160 | | ''' <param name="logName">The name of the event log.</param> |
| | 3161 | | ''' <param name="machineName">The target machine name, or "." for local machine.</param> |
| | 3162 | | ''' <param name="writeAccess">Optional. <c>True</c> to check for write access; otherwise, <c>False</c> for read-only |
| | 3163 | | ''' <returns><c>True</c> if access is permitted; otherwise, <c>False</c>.</returns> |
| 4 | 3164 | | Public Function CanReadRegistryForLog( |
| 4 | 3165 | | ByVal logName As String, |
| 4 | 3166 | | ByVal machineName As String, |
| 4 | 3167 | | Optional ByVal writeAccess As Boolean = False) As Boolean |
| | 3168 | |
|
| 8 | 3169 | | Dim registryPath As String = $"SYSTEM\CurrentControlSet\Services\EventLog\{logName}" |
| | 3170 | |
|
| 8 | 3171 | | Return _registryReader.HasRegistryAccess(RegistryHive.LocalMachine, machineName, registryPath, writeAccess) |
| | 3172 | |
|
| 8 | 3173 | | End Function |
| | 3174 | |
|
| | 3175 | | ''' <summary> |
| | 3176 | | ''' Normalizes the message. |
| | 3177 | | ''' </summary> |
| | 3178 | | ''' <param name="sourceName">Name of the source.</param> |
| | 3179 | | ''' <param name="message">The message.</param> |
| | 3180 | | ''' <returns></returns> |
| 120 | 3181 | | Private Function NormalizeMessage( |
| 120 | 3182 | | ByVal sourceName As String, |
| 120 | 3183 | | ByVal message As String) As String |
| | 3184 | |
|
| 240 | 3185 | | Dim defaultSource As String = Source(sourceName) |
| 240 | 3186 | | Dim finalMessage As String = If(String.IsNullOrEmpty(message), "No message provided.", message.Trim()) |
| 440 | 3187 | | If Not finalMessage.EndsWith("."c) Then finalMessage &= "." |
| 480 | 3188 | | If Not finalMessage.StartsWith("["c) Then finalMessage = $"[{defaultSource}] {finalMessage}" |
| | 3189 | |
|
| | 3190 | | Const maxLength As Integer = 32766 |
| | 3191 | | Const _truncationMarker As String = "... [TRUNCATED]" |
| 240 | 3192 | | Dim marker As String = If(String.IsNullOrEmpty(TruncationMarker), _truncationMarker, TruncationMarker) |
| | 3193 | |
|
| 240 | 3194 | | If finalMessage.Length > maxLength Then |
| | 3195 | | ' Leave room for the truncation marker |
| 48 | 3196 | | Dim maxWithoutMarker As Integer = maxLength - marker.Length |
| 48 | 3197 | | finalMessage = $"{finalMessage.Substring(0, maxWithoutMarker)}{marker}" |
| 144 | 3198 | | End If |
| | 3199 | |
|
| 240 | 3200 | | Return finalMessage |
| | 3201 | |
|
| 240 | 3202 | | End Function |
| | 3203 | |
|
| | 3204 | | ''' <summary> |
| | 3205 | | ''' Splits the message into pages. |
| | 3206 | | ''' </summary> |
| | 3207 | | ''' <param name="sourceName">Name of the source.</param> |
| | 3208 | | ''' <param name="message">The message.</param> |
| | 3209 | | ''' <returns></returns> |
| 8 | 3210 | | Private Function SplitMessageIntoPages( |
| 8 | 3211 | | ByVal sourceName As String, |
| 8 | 3212 | | ByVal message As String) As IEnumerable(Of String) |
| | 3213 | |
|
| | 3214 | | Const maxLength As Integer = 32766 |
| 16 | 3215 | | Dim defaultSource As String = Source(sourceName) |
| 16 | 3216 | | Dim baseMessage As String = message.Trim() |
| 32 | 3217 | | If Not baseMessage.EndsWith("."c) Then baseMessage &= "." |
| | 3218 | |
|
| 16 | 3219 | | Dim cm As String = ContinuationMarker |
| | 3220 | |
|
| 24 | 3221 | | If String.IsNullOrEmpty(cm) Then cm = " ..." |
| | 3222 | |
|
| | 3223 | | ' Initial prefix length calculation |
| | 3224 | | ' Format: "[Source] [Part 999/999] " |
| 16 | 3225 | | Dim maxPartsEstimate As Integer = CInt(Math.Ceiling(baseMessage.Length / (maxLength - 50))) |
| 16 | 3226 | | Dim digitCount As Integer = maxPartsEstimate.ToString().Length + 1 ' pad by 1 digit for safety |
| | 3227 | |
|
| | 3228 | | ' Build conservative prefix sample with max digit placeholders |
| 16 | 3229 | | Dim maxPartsPlaceholder As New String("9"c, digitCount) |
| 16 | 3230 | | Dim prefixSample As String = $"[{defaultSource}] [Part {maxPartsPlaceholder}/{maxPartsPlaceholder}] " |
| | 3231 | | ' Calculate the chunk size by subtracting the prefix length and the space for " ..." at the end of a chunk |
| 16 | 3232 | | Dim chunkSize As Integer = maxLength - prefixSample.Length - cm.Length |
| | 3233 | |
|
| | 3234 | | ' Now split message |
| 16 | 3235 | | Dim parts As New List(Of String) |
| 16 | 3236 | | Dim index As Integer = 0 |
| 48 | 3237 | | While index < baseMessage.Length |
| 32 | 3238 | | Dim len As Integer = Math.Min(chunkSize, baseMessage.Length - index) |
| 32 | 3239 | | parts.Add(baseMessage.Substring(index, len)) |
| 32 | 3240 | | index += len |
| 16 | 3241 | | End While |
| | 3242 | |
|
| | 3243 | | ' Now wrap each chunk with prefix |
| 16 | 3244 | | Dim total As Integer = parts.Count |
| 16 | 3245 | | Dim result As New List(Of String) |
| 16 | 3246 | | For i As Integer = 0 To total - 2 |
| 16 | 3247 | | result.Add($"[{defaultSource}] [Part {i + 1}/{total}] {parts(i)}{cm}") |
| 16 | 3248 | | Next |
| 16 | 3249 | | result.Add($"[{defaultSource}] [Part {total}/{total}] {parts(total - 1)}") |
| | 3250 | |
|
| 16 | 3251 | | Return result |
| | 3252 | |
|
| 16 | 3253 | | End Function |
| | 3254 | |
|
| | 3255 | | ''' <summary> |
| | 3256 | | ''' Normalizes the type of the event. |
| | 3257 | | ''' </summary> |
| | 3258 | | ''' <param name="eventType">Type of the event.</param> |
| | 3259 | | ''' <returns></returns> |
| 148 | 3260 | | Private Function NormalizeEventType( |
| 148 | 3261 | | ByVal eventType As EventLogEntryType) As EventLogEntryType |
| | 3262 | |
|
| 296 | 3263 | | Select Case eventType |
| 112 | 3264 | | Case EventLogEntryType.Error, EventLogEntryType.Warning, EventLogEntryType.Information |
| 224 | 3265 | | Return eventType |
| 36 | 3266 | | Case Else |
| 72 | 3267 | | Return EventLogEntryType.Information |
| | 3268 | | End Select |
| | 3269 | |
|
| 296 | 3270 | | End Function |
| | 3271 | |
|
| | 3272 | | ''' <summary> |
| | 3273 | | ''' Normalizes the name of the machine. |
| | 3274 | | ''' </summary> |
| | 3275 | | ''' <param name="_machineName">Name of the machine.</param> |
| | 3276 | | ''' <returns></returns> |
| 132 | 3277 | | Private Function NormalizeMachineName( |
| 132 | 3278 | | ByVal _machineName As String) As String |
| | 3279 | |
|
| 264 | 3280 | | Return If(String.IsNullOrEmpty(_machineName), If(String.IsNullOrEmpty(MachineName), ".", MachineName), _machineN |
| | 3281 | |
|
| 170 | 3282 | | End Function |
| | 3283 | |
|
| | 3284 | | ''' <summary> |
| | 3285 | | ''' Reads an application setting by key and returns defaultValue |
| | 3286 | | ''' when no setting is found or an error occurs. |
| | 3287 | | ''' </summary> |
| | 3288 | | ''' <param name="key">The key.</param> |
| | 3289 | | ''' <param name="defaultValue">The default value.</param> |
| | 3290 | | ''' <remarks> |
| | 3291 | | ''' On .NET Core / .NET 5+ this method constructs and builds a <see href="ConfigurationBuilder"/> |
| | 3292 | | ''' and reads <c>appsettings.json</c> each time it is invoked. During <c>InitializeConfiguration</c> |
| | 3293 | | ''' this leads to the file being parsed once per recognized key. This is intentional to avoid |
| | 3294 | | ''' static lifetime configuration state; if you need fewer file reads, enable caching |
| | 3295 | | ''' (see caching example). |
| | 3296 | | ''' </remarks> |
| | 3297 | | ''' <returns>The value to be placed in the property associated with the call</returns> |
| 108 | 3298 | | Private Function GetAppSetting( |
| 108 | 3299 | | ByVal key As String, |
| 108 | 3300 | | ByVal defaultValue As String) As String |
| | 3301 | |
|
| | 3302 | | #If NETFRAMEWORK Then |
| | 3303 | | Try |
| | 3304 | | ' .NET Framework: App.config / Web.config |
| | 3305 | | Dim value As String = ConfigurationManager.AppSettings(key) |
| | 3306 | | If String.IsNullOrEmpty(value) Then |
| | 3307 | | Return defaultValue |
| | 3308 | | End If |
| | 3309 | |
|
| | 3310 | | Return value |
| | 3311 | | Catch |
| | 3312 | | Return defaultValue |
| | 3313 | | End Try |
| | 3314 | | #Else |
| | 3315 | | ' .NET Core / .NET 5+ : appsettings.json |
| 216 | 3316 | | Dim builder As New ConfigurationBuilder() |
| 216 | 3317 | | builder.SetBasePath(AppContext.BaseDirectory) |
| 216 | 3318 | | builder.AddJsonFile("appsettings.json", optional:=True, reloadOnChange:=True) |
| 216 | 3319 | | Dim config As IConfigurationRoot = builder.Build() |
| | 3320 | |
|
| 216 | 3321 | | Dim value As String = config(key) |
| 216 | 3322 | | If String.IsNullOrEmpty(value) Then |
| 96 | 3323 | | Return defaultValue |
| 60 | 3324 | | End If |
| | 3325 | |
|
| 120 | 3326 | | Return value |
| | 3327 | | #End If |
| | 3328 | |
|
| 216 | 3329 | | End Function |
| | 3330 | |
|
| | 3331 | | ''' <summary> |
| | 3332 | | ''' Gets the application setting. |
| | 3333 | | ''' </summary> |
| | 3334 | | ''' <param name="key">The key.</param> |
| | 3335 | | ''' <param name="defaultValue">The default value.</param> |
| | 3336 | | ''' <returns></returns> |
| 24 | 3337 | | Private Function GetAppSetting( |
| 24 | 3338 | | ByVal key As String, |
| 24 | 3339 | | ByVal defaultValue As Integer) As Integer |
| | 3340 | |
|
| 48 | 3341 | | Dim raw As String = GetAppSetting(key, defaultValue.ToString()) |
| | 3342 | |
|
| | 3343 | | Dim result As Integer |
| 48 | 3344 | | Return If(Integer.TryParse(raw, result), result, defaultValue) |
| | 3345 | |
|
| 36 | 3346 | | End Function |
| | 3347 | |
|
| | 3348 | | ''' <summary> |
| | 3349 | | ''' Gets the application setting. |
| | 3350 | | ''' </summary> |
| | 3351 | | ''' <param name="key">The key.</param> |
| | 3352 | | ''' <param name="defaultValue">if set to <c>true</c> default value.</param> |
| | 3353 | | ''' <returns></returns> |
| 24 | 3354 | | Private Function GetAppSetting( |
| 24 | 3355 | | ByVal key As String, |
| 24 | 3356 | | ByVal defaultValue As Boolean) As Boolean |
| | 3357 | |
|
| 48 | 3358 | | Dim raw As String = GetAppSetting(key, defaultValue.ToString()) |
| | 3359 | |
|
| | 3360 | | Dim result As Boolean |
| 48 | 3361 | | Return If(Boolean.TryParse(raw, result), result, defaultValue) |
| | 3362 | |
|
| 36 | 3363 | | End Function |
| | 3364 | |
|
| | 3365 | | #End Region |
| | 3366 | |
|
| | 3367 | | #Region " GetLog routines ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
| | 3368 | |
|
| | 3369 | | ''' <summary> |
| | 3370 | | ''' Gets the entry log class to use for writing to the event log. |
| | 3371 | | ''' </summary> |
| | 3372 | | ''' <returns></returns> |
| 4 | 3373 | | Public Function GetLog() As EventLog |
| | 3374 | |
|
| 8 | 3375 | | Initialize() |
| | 3376 | |
|
| 8 | 3377 | | Return GetLog( |
| 8 | 3378 | | SourceName) |
| | 3379 | |
|
| 8 | 3380 | | End Function |
| | 3381 | |
|
| | 3382 | | ''' <summary> |
| | 3383 | | ''' Gets the entry log class to use for writing to the event log. |
| | 3384 | | ''' </summary> |
| | 3385 | | ''' <param name="sourceName"> |
| | 3386 | | ''' The source name to associate with the event log entry. If <c>null</c> or empty, a source is automatically |
| | 3387 | | ''' generated using the calling method's namespace, class, and method name. |
| | 3388 | | ''' If the source exceeds 254 characters, it is automatically truncated. |
| | 3389 | | ''' </param> |
| | 3390 | | ''' <returns></returns> |
| 4 | 3391 | | Public Function GetLog( |
| 4 | 3392 | | ByVal sourceName As String) As EventLog |
| | 3393 | |
|
| 8 | 3394 | | Initialize() |
| | 3395 | |
|
| 8 | 3396 | | Return GetLog( |
| 8 | 3397 | | LogName, |
| 8 | 3398 | | sourceName) |
| | 3399 | |
|
| 8 | 3400 | | End Function |
| | 3401 | |
|
| | 3402 | | ''' <summary> |
| | 3403 | | ''' Gets the entry log class to use for writing to the event log. |
| | 3404 | | ''' </summary> |
| | 3405 | | ''' <param name="logName"> |
| | 3406 | | ''' The name of the event log to write to (e.g., <c>"Application"</c>, <c>"System"</c>, or a custom log name). |
| | 3407 | | ''' If <c>null</c> or empty, the value of the static <c>LogName</c> property is used. |
| | 3408 | | ''' </param> |
| | 3409 | | ''' <param name="sourceName"> |
| | 3410 | | ''' The source name to associate with the event log entry. If <c>null</c> or empty, a source is automatically |
| | 3411 | | ''' generated using the calling method's namespace, class, and method name. |
| | 3412 | | ''' If the source exceeds 254 characters, it is automatically truncated. |
| | 3413 | | ''' </param> |
| | 3414 | | ''' <returns></returns> |
| 28 | 3415 | | Public Function GetLog( |
| 28 | 3416 | | ByVal logName As String, |
| 28 | 3417 | | ByVal sourceName As String) As EventLog |
| | 3418 | |
|
| 56 | 3419 | | Initialize() |
| | 3420 | |
|
| 56 | 3421 | | Return GetLog( |
| 56 | 3422 | | logName, |
| 56 | 3423 | | sourceName, |
| 56 | 3424 | | MaxKilobytes, |
| 56 | 3425 | | RetentionDays) |
| | 3426 | |
|
| 56 | 3427 | | End Function |
| | 3428 | |
|
| | 3429 | | ''' <summary> |
| | 3430 | | ''' Gets the entry log class to use for writing to the event log. |
| | 3431 | | ''' </summary> |
| | 3432 | | ''' <param name="logName"> |
| | 3433 | | ''' The name of the event log to write to (e.g., <c>"Application"</c>, <c>"System"</c>, or a custom log name). |
| | 3434 | | ''' If <c>null</c> or empty, the value of the static <c>LogName</c> property is used. |
| | 3435 | | ''' </param> |
| | 3436 | | ''' <param name="sourceName"> |
| | 3437 | | ''' The source name to associate with the event log entry. If <c>null</c> or empty, a source is automatically |
| | 3438 | | ''' generated using the calling method's namespace, class, and method name. |
| | 3439 | | ''' If the source exceeds 254 characters, it is automatically truncated. |
| | 3440 | | ''' </param> |
| | 3441 | | ''' <param name="maxKilobytes"> |
| | 3442 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 3443 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 3444 | | ''' </param> |
| | 3445 | | ''' <param name="retentionDays"> |
| | 3446 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 3447 | | ''' Only used when creating a new log. |
| | 3448 | | ''' </param> |
| | 3449 | | ''' <returns></returns> |
| 28 | 3450 | | Public Function GetLog( |
| 28 | 3451 | | ByVal logName As String, |
| 28 | 3452 | | ByVal sourceName As String, |
| 28 | 3453 | | ByVal maxKilobytes As Integer, |
| 28 | 3454 | | ByVal retentionDays As Integer) As EventLog |
| | 3455 | |
|
| 56 | 3456 | | Initialize() |
| | 3457 | |
|
| 56 | 3458 | | Return GetLog( |
| 56 | 3459 | | logName, |
| 56 | 3460 | | sourceName, |
| 56 | 3461 | | maxKilobytes, |
| 56 | 3462 | | retentionDays, |
| 56 | 3463 | | WriteInitEntry) |
| | 3464 | |
|
| 56 | 3465 | | End Function |
| | 3466 | |
|
| | 3467 | | ''' <summary> |
| | 3468 | | ''' Gets the entry log class to use for writing to the event log. |
| | 3469 | | ''' </summary> |
| | 3470 | | ''' <param name="logName"> |
| | 3471 | | ''' The name of the event log to write to (e.g., <c>"Application"</c>, <c>"System"</c>, or a custom log name). |
| | 3472 | | ''' If <c>null</c> or empty, the value of the static <c>LogName</c> property is used. |
| | 3473 | | ''' </param> |
| | 3474 | | ''' <param name="sourceName"> |
| | 3475 | | ''' The source name to associate with the event log entry. If <c>null</c> or empty, a source is automatically |
| | 3476 | | ''' generated using the calling method's namespace, class, and method name. |
| | 3477 | | ''' If the source exceeds 254 characters, it is automatically truncated. |
| | 3478 | | ''' </param> |
| | 3479 | | ''' <param name="maxKilobytes"> |
| | 3480 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 3481 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 3482 | | ''' </param> |
| | 3483 | | ''' <param name="retentionDays"> |
| | 3484 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 3485 | | ''' Only used when creating a new log. |
| | 3486 | | ''' </param> |
| | 3487 | | ''' <param name="writeInitEntry"> |
| | 3488 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 3489 | | ''' </param> |
| | 3490 | | ''' <returns></returns> |
| 28 | 3491 | | Public Function GetLog( |
| 28 | 3492 | | ByVal logName As String, |
| 28 | 3493 | | ByVal sourceName As String, |
| 28 | 3494 | | ByVal maxKilobytes As Integer, |
| 28 | 3495 | | ByVal retentionDays As Integer, |
| 28 | 3496 | | ByVal writeInitEntry As Boolean) As EventLog |
| | 3497 | |
|
| 56 | 3498 | | Initialize() |
| | 3499 | |
|
| 56 | 3500 | | Return GetLog( |
| 56 | 3501 | | MachineName, |
| 56 | 3502 | | logName, |
| 56 | 3503 | | sourceName, |
| 56 | 3504 | | maxKilobytes, |
| 56 | 3505 | | retentionDays, |
| 56 | 3506 | | writeInitEntry) |
| | 3507 | |
|
| 56 | 3508 | | End Function |
| | 3509 | |
|
| | 3510 | | ''' <summary> |
| | 3511 | | ''' Gets the entry log class to use for writing to the event log. |
| | 3512 | | ''' </summary> |
| | 3513 | | ''' <param name="machineName"> |
| | 3514 | | ''' The name of the machine where the event log resides. Use <c>"."</c> to refer to the local machine. |
| | 3515 | | ''' If <c>null</c> or empty, the local machine is used by default, or the value in <c>MachinName</c> if set. |
| | 3516 | | ''' </param> |
| | 3517 | | ''' <param name="logName"> |
| | 3518 | | ''' The name of the event log to write to (e.g., <c>"Application"</c>, <c>"System"</c>, or a custom log name). |
| | 3519 | | ''' If <c>null</c> or empty, the value of the static <c>LogName</c> property is used. |
| | 3520 | | ''' </param> |
| | 3521 | | ''' <param name="sourceName"> |
| | 3522 | | ''' The source name to associate with the event log entry. If <c>null</c> or empty, a source is automatically |
| | 3523 | | ''' generated using the calling method's namespace, class, and method name. |
| | 3524 | | ''' If the source exceeds 254 characters, it is automatically truncated. |
| | 3525 | | ''' </param> |
| | 3526 | | ''' <param name="maxKilobytes"> |
| | 3527 | | ''' The maximum size of the event log in kilobytes. Only used when creating a new log. |
| | 3528 | | ''' Must be between 64 KB and 4 GB. If 0 or negative, the system default is used. |
| | 3529 | | ''' </param> |
| | 3530 | | ''' <param name="retentionDays"> |
| | 3531 | | ''' The number of days to retain event log entries. If 0, events are retained indefinitely. |
| | 3532 | | ''' Only used when creating a new log. |
| | 3533 | | ''' </param> |
| | 3534 | | ''' <param name="writeInitEntry"> |
| | 3535 | | ''' Indicates whether an initialization entry should be written when a new log is created. |
| | 3536 | | ''' </param> |
| | 3537 | | ''' <returns></returns> |
| 28 | 3538 | | Public Function GetLog( |
| 28 | 3539 | | ByVal machineName As String, |
| 28 | 3540 | | ByVal logName As String, |
| 28 | 3541 | | ByVal sourceName As String, |
| 28 | 3542 | | ByVal maxKilobytes As Integer, |
| 28 | 3543 | | ByVal retentionDays As Integer, |
| 28 | 3544 | | ByVal writeInitEntry As Boolean) As EventLog |
| | 3545 | |
|
| 56 | 3546 | | Initialize() |
| | 3547 | |
|
| 56 | 3548 | | Return _writer.GetLog( |
| 56 | 3549 | | NormalizeMachineName(machineName), |
| 56 | 3550 | | logName, |
| 56 | 3551 | | sourceName, |
| 56 | 3552 | | maxKilobytes, |
| 56 | 3553 | | retentionDays, |
| 56 | 3554 | | writeInitEntry) |
| | 3555 | |
|
| 56 | 3556 | | End Function |
| | 3557 | |
|
| | 3558 | | #End Region |
| | 3559 | |
|
| | 3560 | | End Module |