Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6649469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:46:39+00:00 2026-05-26T00:46:39+00:00

I am testing Log4Net and have been able to write to text files, event

  • 0

I am testing Log4Net and have been able to write to text files, event viewers. I was trying to test it with MS SQL 2008 Express and I cannot seem to get it to insert into the DB I have created locally.

Instance: (local)

DB Name: Log4Net

I have omitted the User Id and Password on the connection string in the config below as I am running it locally:

<log4net debug="true">
        <!--
            APPENDING TO A TEXT FILE
        -->
        <!--<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="C:\\Log4Net\\TestLog.txt" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="10" />
            <maximumFileSize value="10MB" />
            <staticLogFileName value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
            </layout>
        </appender>-->

        <!--
            WRITING TO THE EVENT LOG
        -->
        <!--<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
            <applicationName value="Log4Net Test" />
            <layout type="log4net.Layout.PatternLayout">
                --><!--<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />--><!--
                <conversionPattern value="%date - %message%newline" />
            </layout>
        </appender>-->

        <!--
            WRITING TO MS SQL
        -->
        <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
            <bufferSize value="100" />
            <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <connectionString value="data source=(local);initial catalog=Log4Net;integrated security=false;persist security info=True" />
            <commandText value="INSERT INTO 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>
        </appender>



        <root>
            <level value="DEBUG" />
            <appender-ref ref="AdoNetAppender" />
        </root>
    </log4net>

Here is the test C# code:

 if (log.IsDebugEnabled)
                {
                    log.Debug("Insert some useful comment..");
                }

                if (log.IsErrorEnabled)
                {
                    log.Error("Some Error blah blah.. Testing Only..");
                }

P.S.
I definitely have created the ‘Log’ table already.

Link to config examples: http://logging.apache.org/log4net/release/config-examples.html

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:46:40+00:00Added an answer on May 26, 2026 at 12:46 am

    If you want to omit user id and password from the connection string, you need to set integrated security=true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows form App which write to log files using log4net. The
I am trying to write a unit test to cover code found in our
Testing: return request.getCookies() == null; is not an appropriate way test. Is there another
Unit testing is, roughly speaking, testing bits of your code in isolation with test
For testing purposes I have to generate a file of a certain size (to
for testing purposes i need an recursive directory with some files, that comes to
Fot testing iPhone apps, is it a bad idea to have a development code
I'm testing NServiceBus on ASP.NET MVC3. At the moment, I'm able to send command
A suite of integration services that use NServiceBus have been dropped in my lap
I tried to configure log4net for logging everything to the console output. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.