• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

log4net setup.

http://weblogs.asp.net/drnetjes/archive/2005/02/16/374780.aspx
I created a file called log4net.config.
--------------------------------------------
<?xml version="1.0"?>
<log4net>

  <appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
    <bufferSize value="1" />
    <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <connectionString value="Data Source=72.18.146.251,1533;Initial Catalog=omegalove;Persist Security Info=True;User ID=administrator;Password=...." providerName="System.Data.SqlClient" />
    <commandText value="INSERT INTO Log ([Date],[Level],[Logger],[User],[Message],[Exception]) VALUES (@log_date, @log_level, @logger, @user, @message, @exception)" />
    <parameter>
      <parameterName value="@log_date" />
      <dbType value="DateTime" />
      <layout type="log4net.Layout.RawTimeStampLayout" />
    </parameter>
    <parameter>
      <parameterName value="@log_level" />
      <dbType value="String" />
      <size value="50" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%p" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@logger" />
      <dbType value="String" />
      <size value="255" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%c" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@user" />
      <dbType value="String" />
      <size value="50" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%X{user}" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@message" />
      <dbType value="String" />
      <size value="4000" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%m" />
      </layout>
    </parameter>
    <parameter>
      <parameterName value="@exception" />
      <dbType value="String" />
      <size value="2000" />
      <layout type="log4net.Layout.ExceptionLayout" />
    </parameter>
  </appender>

  <root>
    <level value="ALL" />
    <appender-ref ref="ADONetAppender" />
  </root>
</log4net>

1 st question is how to I reference this, I do not have an app_code directory.
2 nd is how can I test this.
I am confused by the article. Where the hell does this go?
public void LogError (string message, Exception e){  //get logger  ILog logger = LogManager.GetLogger("MyProject");    //set user to log4net context, so we can use %X{user} in the appenders  if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)    MDC.Set("user", HttpContext.Current.User.Identity.Name);   if (logger.IsErrorEnabled)    logger.Error(message, e); //now log error}
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Log]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
 BEGIN
CREATE TABLE [dbo].[Log] ( [Id] [int] IDENTITY (1, 1) NOT NULL, [Date] [datetime] NOT NULL, [Thread] [varchar] (255) NOT NULL, [Level] [varchar] (50) NOT NULL, [Logger] [varchar] (255) NOT NULL, [User] [varchar] (50) NULL, [Message] [varchar] (4000) NOT NULL, [Exception] [varchar] (2000) NULL)

Open in new window

0
omegalove
Asked:
omegalove
  • 3
1 Solution
 
omegaloveAuthor Commented:
I have this in my webconfig
 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
   
Now how do I setup the rest.
0
 
omegaloveAuthor Commented:
U just are giving me other approaches.
I would like to folloaw one standard,
0
 
omegaloveAuthor Commented:
k
0
 
CodeCruiserCommented:
> Where the hell does this go?
I guess that code is actually logging an error so it would go in a test page.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now