Advertisement

03.10.2008 at 11:25PM PDT, ID: 23230933
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Problems with Log4Net

Asked by fuchangmiao in Microsoft Visual C#.Net, Microsoft Visual Basic.Net

Tags:

Hi, I am trying to get rid of the connectionstring in web.config for log4net, and trying to handle the connectionstring in code. Here is what I got in code snippet.

It was working before my changes, all I did was:

1. put the following in the Application_Start in global.asax.vb
2. got rid of connectionstring in web.config under log4net node

But I cannot get it to work. it saves to the file, but it just wouldn't save to the database.

Any idea?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Fires when the application is started
 
      
        Try
                        log4net.Config.DOMConfigurator.Configure()
 
            Dim h As log4net.Repository.Hierarchy.Hierarchy = TryCast(LogManager.GetLoggerRepository(), log4net.Repository.Hierarchy.Hierarchy)
            'get the ADO appender 
            Dim ado As log4net.Appender.ADONetAppender = TryCast(h.Root.GetAppender("CMErrorEmailDBLog"), log4net.Appender.ADONetAppender)
            ado.ConnectionString = "whatever your connection string is"
            ado.ActivateOptions()
 
        Catch nfe As NullReferenceException
            Throw New NullReferenceException("log4net configuration could not be completed. " & Chr(10) & "Do you have your app.config set up properly?", nfe)
        End Try
 
    End Sub
 
<log4net>
    <appender name="CMError" type="log4net.Appender.RollingFileAppender">
      <file value="Logs\\cmdotnet.log"/>
      <appendToFile value="true"/>
      <maximumFileSize value="1024KB"/>
      <maxSizeRollBackups value="5"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t]\n%-5p\n%c\n%x\n%m%n\n=============================================\n"/>
      </layout>
    </appender>
 
    <appender name="CMErrorEmail" type="log4net.Appender.SmtpAppender" additivity="false">
      <to value="" />
      <!-- Should be configured to send to admin -->
      <from value="logger@test.com.au" />
      <subject value="Failed!" />
      <smtpHost value="mail.test.com.au" />
      <bufferSize value="256" />
      <lossy value="false" />
      <threshold value="DEBUG" />
      <evaluator type="log4net.Core.LevelEvaluator,log4net">
        <threshold value="ERROR" />
      </evaluator>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <conversionPattern value="%-5p %d [ThreadId: %t] Class:%c{1} Method:%M %nMESSAGE:%n%m%n%n" />
      </layout>
      <level value="ERROR" />
    </appender>
 
    <appender name="CMErrorEmailDBLog" type="log4net.Appender.AdoNetAppender" additivity="false">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <commandText value="INSERT INTO [dbo].[Log] ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value="@thread" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%thread" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@logger" />
        <dbType value="String" />
        <size value="255" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@exception" />
        <dbType value="String" />
        <size value="2000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
      <level value="ERROR" />
    </appender>
 
    <root>
      <level value="INFO"/>
      <appender-ref ref="CMError"/>
      <appender-ref ref="CMErrorEmail"/>
      <appender-ref ref="CMErrorEmailDBLog"/>
    </root>
  </log4net>
[+][-]03.11.2008 at 12:14PM PDT, ID: 21099001

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, Microsoft Visual Basic.Net
Tags: C#, vb.net
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: B
 
 
[+][-]03.11.2008 at 03:08PM PDT, ID: 21100908

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.11.2008 at 04:32PM PDT, ID: 21101513

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.11.2008 at 10:12PM PDT, ID: 21103201

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628