Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm using log4net to log in my WPF MVVM application.
I've different type of log like application,network etc that logs in different folders using different log4net Config files.Each time when the application tries to log I'm configuring the log4net(Both file appender and mail).

Is it a right way?
Is there any way to keep this configuration in a common place and only update whenever a change occurs?
Posted

If you're doing the configuration from within your code this is definitely not advisable. You can have all you configurations within one log4net configuration file. All you have to agree on is a naming scheme for your configurations that will avoid collisions. One way to achieve this is to have a naming scheme that relies on the fully qualified type name. You'll have to read up on this, but as a far as I remember you don't need to have a configuration for each and every class as the log4net naming scheme allows for wildcards:
If you want one logger for all classes in a namespace like net.Atos.Search.Query.Result you can specify the configuration with net.Atos.Search.Query.Result.*.

Hope that helps! Please look into the log4net documentation for details.

Regards,

—MRB
 
Share this answer
 
v2
You can catch all your application errors in Global File on application error event.



If any error occured in application it will throgh the error on this event.you need not catach exception for each function


Something Like this :::

VB
Protected Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    Dim ex As Exception = Server.GetLastError()
    Server.ClearError()
    If (Not ex Is DBNull.Value) Then
        Dim logger As ILog = LogManager.GetLogger(GetType(Global.TopItems.Globalasax))
        logger.Error(ex.Message, ex)
    End If

    If (TypeOf ex Is HttpRequestValidationException) Then
        Response.Redirect("~/ErrorDisplay.aspx?ErrMsg=InvalidInput", True)
    ElseIf (Not ex.InnerException Is Nothing) Then
        If (ex.InnerException.Message.Contains("TCP error code")) Then
            Response.Redirect("~/ErrorDisplay.aspx?ErrMsg=SERVICENOTAVILABLE", True)
        End If
    Else
        Response.Redirect("~/ErrorDisplay.aspx", True)
    End If

End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900