ASP.NET - Applicationlog - Asked By lakshmi chaitanya on 04-Jan-12 01:56 AM

HI
   how to create an application log in global.asax page
Suchit shah replied to lakshmi chaitanya on 04-Jan-12 01:59 AM
Please have a look on below articles.... i just recentrly read to add global exception handling and this will be also help to you also
http://www.codeguru.com/csharp/.net/net_debugging/article.php/c19411
http://www.shubho.net/2011/01/exception-handling-best-practices-in-n.html
http://www.codeproject.com/KB/aspnet/JcGlobalErrorHandling.aspx
http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx
http://blog.dreamlabsolutions.com/post/2008/10/01/ASPnet-global-exception-handling-and-custom-error-page.aspx
http://www.asp.net/web-forms/tutorials/deployment/logging-error-details-with-elmah-cs
Jitendra Faye replied to lakshmi chaitanya on 04-Jan-12 02:02 AM
You can create this using EventLog class.

follow this code-


private void btnCreateEventLog_Click(object sender, System.EventArgs e) {
 if (txtEventLog.Text.Length > 0 && txtEventSource.Text.Length > 0) { System.Diagnostics.EventLog.CreateEventSource(
txtEventSource.Text, txtEventLog.Text);
MessageBox.Show("Event Log and Source " +
"created successfully.");
} else { MessageBox.Show("Please fill in both the " +
"Event Log and the Event Source.");
}
}
Riley K replied to lakshmi chaitanya on 04-Jan-12 02:04 AM


In the application error event handle eventlog

void Application_Error(object sender, EventArgs e)
  {
    // Obtain the URL of the request
    string url = Request.Path;
 
    // Obtain the Exception object describing the error
    Exception error = Server.GetLastError();
 
    // Build the message --> [Error occurred. XXX at url]
    StringBuilder text = new StringBuilder("Error occurred. ");
    text.Append(error.Message);
    text.Append(" at ");
    text.Append(url);
 
    // Write to the Event Log
    EventLog log = new EventLog();
    log.Source = "Core35 Log";
     // log.WriteEntry(text.ToString(), EventLogEntryType.Error);
  }


Regards
dipa ahuja replied to lakshmi chaitanya on 04-Jan-12 02:51 AM
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    Dim username As String = Session("logonName")
    Dim mylog As myNameSpace.MyLogClass = New myNameSpace.MyLogClass(Server.MapPath("log"), "UserLog")
    mylog .Write("test")
    If username IsNot Nothing Then
      Dim user As MembershipUser = Membership.GetUser(username)
      user.LastActivityDate = New DateTime(1900, 1, 1)
      Membership.Provider.UpdateUser(user)
    End If
End Sub
Sri K replied to lakshmi chaitanya on 04-Jan-12 03:42 AM
For Database side, In CP you can find many articles. Here you go
http://www.codeproject.com/KB/database/AuditTrailGenerator.aspx[http://www.codeproject.com/KB/database/AuditTrailGenerator.aspx]
http://www.codeproject.com/KB/aspnet/ImplementingAudit.aspx[http://www.codeproject.com/KB/aspnet/ImplementingAudit.aspx]
http://www.codeproject.com/Articles/90361/Auditing-events-on-SQL-Server-2008.aspx[http://www.codeproject.com/Articles/90361/Auditing-events-on-SQL-Server-2008.aspx]
http://www.codeproject.com/KB/database/Tracing-Data-Changes.aspx[http://www.codeproject.com/KB/database/Tracing-Data-Changes.aspx]
http://www.codeproject.com/KB/database/AuditsOnMSSQLServer.aspx[http://www.codeproject.com/KB/database/AuditsOnMSSQLServer.aspx]
For application side you may use the below one
http://www.codeproject.com/Tips/237171/Five-methods-to-Logging-in-MVC-3-0[http://www.codeproject.com/Tips/237171/Five-methods-to-Logging-in-MVC-3-0]
kalpana aparnathi replied to lakshmi chaitanya on 04-Jan-12 04:38 AM
HI,

Try this code:


public class SoapExceptionHandler : System.Web.Services.Protocols.SoapExtension
{
public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterSerialize)
{
if (message.Exception != null)
{
Logger.Write(message.Exception.InnerException);
}
}
}
public override object GetInitializer(Type serviceType)
{
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo,
 SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer){ }
}
 
[AttributeUsage(AttributeTargets.Method)]
public class ExceptionHandlingAttribute : SoapExtensionAttribute
{
public override Type ExtensionType{get { return typeof(SoapExceptionHandler); }}
public override int Priority{get{return 0;}set{}}
}
You can apply this attribute to your XML Web service methods and thus enable your newly created SoapExtension.
 
[WebMethod] [ExceptionHandling] public void Foo(){}