/// <summary> /// process a raised event /// </summary> /// <param name="eventRaised">the event to be processed</param> public override void ProcessEvent(WebBaseEvent eventRaised) { if (eventRaised == null) { throw new ArgumentNullException("eventRaised"); } if (UseBuffering) { base.ProcessEvent(eventRaised); } else { string extraInfo = string.Empty; WebBaseErrorEvent errorEvent = eventRaised as WebBaseErrorEvent; if (errorEvent != null) { extraInfo = errorEvent.ErrorException.ToString(); } this.customInfo.AppendLine( string.Format( CultureInfo.InvariantCulture, "Event Time (UTC):[{0}] Event Code:[{1}] Event Id:[{2}] Event Message:[{3}]", eventRaised.EventTimeUtc, eventRaised.EventCode, eventRaised.EventID, eventRaised.Message + " " + extraInfo)); this.StoreToFile(FileMode.Append); } }
/// <summary> /// Processes the buffered events. /// </summary> /// <param name="flushInfo">A <see cref="T:System.Web.Management.WebEventBufferFlushInfo"/> that contains buffering information.</param> public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo) { if (flushInfo == null) { throw new ArgumentNullException("flushInfo"); } foreach (WebBaseEvent eventRaised in flushInfo.Events) { string extraInfo = string.Empty; WebBaseErrorEvent webBasedErrorEvent = eventRaised as WebBaseErrorEvent; if (webBasedErrorEvent != null) { extraInfo = webBasedErrorEvent.ErrorException.ToString(); } string line = string.Format( CultureInfo.InvariantCulture, "Event Time (UTC):[{0}] Event Code:[{1}] Event Id:[{2}] Event Message:[{3}]", eventRaised.EventTimeUtc, eventRaised.EventCode, eventRaised.EventID, eventRaised.Message + " " + extraInfo); if (this.Name == "ErrorEventProvider") { Console.Error.WriteLine(line); } else { Console.Out.WriteLine(line); } } }
/// <summary> /// Processes the buffered events. /// </summary> /// <param name="flushInfo">A <see cref="T:System.Web.Management.WebEventBufferFlushInfo"/> that contains buffering information.</param> public override void ProcessEventFlush(WebEventBufferFlushInfo flushInfo) { if (flushInfo == null) { throw new ArgumentNullException("flushInfo"); } foreach (WebBaseEvent eventRaised in flushInfo.Events) { string extraInfo = string.Empty; WebBaseErrorEvent webBasedErrorEvent = eventRaised as WebBaseErrorEvent; if (webBasedErrorEvent != null) { extraInfo = webBasedErrorEvent.ErrorException.ToString(); } this.customInfo.AppendLine( string.Format( CultureInfo.InvariantCulture, "Event Time (UTC):[{0}] Event Code:[{1}] Event Id:[{2}] Event Message:[{3}]", eventRaised.EventTimeUtc, eventRaised.EventCode, eventRaised.EventID, eventRaised.Message + " " + extraInfo)); } this.StoreToFile(FileMode.Append); }
private static Exception GetExceptionFromWebEvent(WebBaseEvent eventRaised) { WebBaseErrorEvent errorEvent = eventRaised as WebBaseErrorEvent; if (errorEvent != null) { return(errorEvent.ErrorException); } return(null); }
/// <summary> /// Processes the event passed to the provider. /// </summary> /// <param name="raisedEvent"></param> public override void ProcessEvent(WebBaseEvent raisedEvent) { //make SURE we're really running in the web server so we don't mess up aspnet_compiler. if (m_NotInAspNet) { return; } try { //lets see if this is an event we're going to ignore to keep the log clean. if (raisedEvent.EventCode == WebEventCodes.AuditUrlAuthorizationSuccess) { return; //this is an ignorable audit success, who cares. } if (raisedEvent.EventCode == WebEventCodes.AuditFileAuthorizationSuccess) { return; //this is an ignorable audit success, who cares. } if (raisedEvent.EventCode == WebEventCodes.ApplicationHeartbeat) { return; //the user has other ways of knowing we're alive, we don't want to record this. } if (raisedEvent.EventCode == WebEventCodes.ApplicationShutdown) { //call end session and tell it our sucess information Log.EndSession(SessionStatus.Normal, raisedEvent.Message); return; } string categoryName = "System.Events." + GetEventCodeCategoryName(raisedEvent.EventCode); string caption = raisedEvent.Message; string description = null; Exception exception = null; LogMessageSeverity severity; Uri requestUri = null; WebProcessInformation processInformation = null; WebRequestInformation requestInformation = null; WebThreadInformation threadInformation = null; //process types we explicitly understand first if (raisedEvent is WebSuccessAuditEvent) { //it's an otherwise unknown inheritor of the success event, treat it as such. WebSuccessAuditEvent specificEvent = raisedEvent as WebSuccessAuditEvent; severity = LogMessageSeverity.Verbose; processInformation = specificEvent.ProcessInformation; requestInformation = specificEvent.RequestInformation; } else if (raisedEvent is WebViewStateFailureAuditEvent) { //it's an otherwise unknown inheritor of the failure audit event, treat it as such. WebViewStateFailureAuditEvent specificEvent = raisedEvent as WebViewStateFailureAuditEvent; severity = LogMessageSeverity.Error; exception = specificEvent.ViewStateException; GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier. processInformation = specificEvent.ProcessInformation; requestInformation = specificEvent.RequestInformation; } else if (raisedEvent is WebFailureAuditEvent) { //it's an otherwise unknown inheritor of the failure event, treat it as such. WebFailureAuditEvent specificEvent = raisedEvent as WebFailureAuditEvent; severity = LogMessageSeverity.Warning; processInformation = specificEvent.ProcessInformation; requestInformation = specificEvent.RequestInformation; } else if (raisedEvent is WebRequestEvent) { //it's an otherwise unknown inheritor of the request event, treat it as such. WebRequestEvent specificEvent = raisedEvent as WebRequestEvent; severity = LogMessageSeverity.Information; processInformation = specificEvent.ProcessInformation; requestInformation = specificEvent.RequestInformation; } else if (raisedEvent is WebRequestErrorEvent) { //it's an otherwise unknown inheritor of the request error event, treat it as such. WebRequestErrorEvent specificEvent = raisedEvent as WebRequestErrorEvent; severity = LogMessageSeverity.Error; exception = specificEvent.ErrorException; GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier. processInformation = specificEvent.ProcessInformation; requestInformation = specificEvent.RequestInformation; threadInformation = specificEvent.ThreadInformation; } else if (raisedEvent is WebErrorEvent) { //it's an otherwise unknown inheritor of the error event, treat it as such. WebErrorEvent specificEvent = raisedEvent as WebErrorEvent; severity = LogMessageSeverity.Error; exception = specificEvent.ErrorException; GenerateLogMessage(exception, ref caption, ref description); //override the generic caption we created earlier. processInformation = specificEvent.ProcessInformation; requestInformation = specificEvent.RequestInformation; threadInformation = specificEvent.ThreadInformation; } else if (raisedEvent is WebBaseErrorEvent) { //it's an otherwise unknown inheritor of the base error event, treat it as such. WebBaseErrorEvent specificEvent = raisedEvent as WebBaseErrorEvent; exception = specificEvent.ErrorException; severity = LogMessageSeverity.Error; processInformation = specificEvent.ProcessInformation; } else if (raisedEvent is WebApplicationLifetimeEvent) { WebApplicationLifetimeEvent specificEvent = raisedEvent as WebApplicationLifetimeEvent; //we use different severities for two scenarios: Compilation and startup/shutdown if ((raisedEvent.EventCode == WebEventCodes.ApplicationCompilationStart) || (raisedEvent.EventCode == WebEventCodes.ApplicationCompilationEnd)) { severity = LogMessageSeverity.Verbose; } else { severity = LogMessageSeverity.Information; } processInformation = specificEvent.ProcessInformation; } else if (raisedEvent is WebManagementEvent) { //it's an otherwise unknown inheritor of the management event, treat it as such. WebManagementEvent specificEvent = raisedEvent as WebManagementEvent; severity = LogMessageSeverity.Information; processInformation = specificEvent.ProcessInformation; } else { //overly simple initial implementation severity = LogMessageSeverity.Information; } //see if we can populate more fields based on ASP-NET objects string userName = null; if (processInformation != null) { userName = processInformation.AccountName; } if (threadInformation != null) { //thread user name better than process user name userName = threadInformation.ThreadAccountName; } string detailsXml = null; if (requestInformation != null) { //if there is a current principal, that's our favorite answer. IPrincipal currentPrincipal = requestInformation.Principal; IIdentity currentIdentity = null; if (currentPrincipal != null) { currentIdentity = currentPrincipal.Identity; } userName = currentIdentity != null ? currentIdentity.Name : requestInformation.ThreadAccountName; detailsXml = GetRequestXml(requestInformation); if (string.IsNullOrEmpty(requestInformation.RequestUrl) == false) { try { requestUri = new Uri(requestInformation.RequestUrl); } catch (Exception ex) { GC.KeepAlive(ex); #if DEBUG Log.RecordException(ex, "System", true); #endif } } } //three ways we create our message source provider: Exception (best), Thread info (gotta parse, but accurate), and Request INfo (fake location) IMessageSourceProvider requestSource = null; if (exception != null) { requestSource = new ExceptionSourceProvider(exception); } else if (requestInformation != null) { requestSource = new WebRequestSourceProvider(requestInformation, requestUri); } else if (raisedEvent.EventSource != null) { requestSource = new WebRequestSourceProvider(raisedEvent.EventSource); } //if we haven't figured out a class name by now, BS it using our event source. if ((requestSource as WebRequestSourceProvider != null) && (string.IsNullOrEmpty(requestSource.ClassName) && (raisedEvent.EventSource != null))) { (requestSource as WebRequestSourceProvider).SetSource(raisedEvent.EventSource); } Log.Write(severity, LogSystem, requestSource, userName, exception, LogWriteMode.Queued, detailsXml, categoryName, caption, description); } catch (Exception ex) { GC.KeepAlive(ex); #if DEBUG Log.RecordException(ex, "System", true); #endif } }