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

  • Home
  • SEARCH
  • 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 55475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:22:59+00:00 2026-05-10T17:22:59+00:00

Backstory: I’m using log4net to handle all logging for a project I’m working on.

  • 0

Backstory: I’m using log4net to handle all logging for a project I’m working on. One particular method can be called under several different circumstances — some that warrant the log messages to be errors and others that warrant the log messages to be warnings.

So, as an example, how could I turn

Public Sub CheckDifference(ByVal A As Integer, ByVal B As Integer)   If (B - A) > 5 Then     log.ErrorFormat('Difference ({0}) is outside of acceptable range.', (B - A))   End If End Sub 

Into something more along the lines of:

Public Sub CheckDifference(ByVal A As Integer, ByVal B As Integer, 'Some delegate info here')   If (B - A) > 5 Then     **delegateinfo**.Invoke('Difference ({0}) is outside of acceptable range.', (B - A))   End If End Sub 

So that I could call it and pass either log.ErrorFormat or log.WarnFormat as the delegate?

I’m using VB.NET with VS 2008 and .NET 3.5 SP1. Also, I’m fairly new to delegates in general, so if this question should be worded differently to remove any ambiguities, let me know.

EDIT: Also, how could I initialize the delegate to either the ErrorFormat or the WarnFormat in the class constructor? Would it be as easy as myDelegate = log.ErrorFormat? I would imagine there is more to it than that (pardon my ignorance on the subject — delegates are really something I want to learn more about, but so far they have eluded my understanding).

  • 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. 2026-05-10T17:23:00+00:00Added an answer on May 10, 2026 at 5:23 pm

    Declare your delegate signature:

    Public Delegate Sub Format(ByVal value As String) 

    Define your Test function:

    Public Sub CheckDifference(ByVal A As Integer, _                            ByVal B As Integer, _                            ByVal format As Format)     If (B - A) > 5 Then         format.Invoke(String.Format( _         'Difference ({0}) is outside of acceptable range.', (B - A)))     End If End Sub 

    Somewhere in your code call your Test function:

    CheckDifference(Foo, Bar, AddressOf log.WriteWarn) 

    Or

    CheckDifference(Foo, Bar, AddressOf log.WriteError) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I recall struggling with this issue long ago, wondering why… May 11, 2026 at 3:03 pm
  • added an answer The functions you want are 'encode-time, 'format-time-string, and 'decode-time. For… May 11, 2026 at 3:03 pm
  • added an answer That's a very general question. What is 'an external file'… May 11, 2026 at 3:03 pm

Related Questions

Backstory: I'm using log4net to handle all logging for a project I'm working on.
Backstory: I have a PKCS#12 (p12) certificate with a symmetric cipher (password) that I
Backstory I'm on Rails 2.1 and need to freeze the Capistrano gem to my
The backstory: I am applying a filter to a TableView. It's a simple 'find
A bit of backstory: I am working on an web application that requires quite

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.