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 8319825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:26:37+00:00 2026-06-08T22:26:37+00:00

I have an azure worker role which I have configured to use a log4net

  • 0

I have an azure worker role which I have configured to use a log4net Trace Appender which writes to WindowsAzure.Diagnostics. This is done by making the following calls in the RoleEntryPoint of the worker role.

using System;
using Microsoft.WindowsAzure.Diagnostics;
using log4net.Config;

namespace XXX
{
    public class WorkerRole : RoleEntryPoint
    {
        public override bool OnStart()
        {
            var config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Warning;
            config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);

            config.WindowsEventLog.DataSources.Add("System!*");
            config.WindowsEventLog.DataSources.Add("Application!*");
            config.WindowsEventLog.ScheduledTransferLogLevelFilter = LogLevel.Error;
            config.WindowsEventLog.ScheduledTransferPeriod = TimeSpan.FromMinutes(5);

            DiagnosticMonitor.Start("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString", config);

        XmlConfigurator.Configure();
        }
    }
}

The App.config file is configured in the following manner:

<log4net>
    <appender name="TraceAppender" type="log4net.Appender.TraceAppender">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%logger - %message" />
        </layout>
    </appender>
    <root>
        <level value="ALL" />
        <appender-ref ref="TraceAppender" />
    </root>
</log4net>

<system.diagnostics>
    <trace>
        <listeners>
            <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
                <filter type="" />
            </add>
        </listeners>
    </trace>
</system.diagnostics>

The result of this is that all messages (even errors) are logged in table storage as “verbose” level.

How to fix this?

  • 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-06-08T22:26:38+00:00Added an answer on June 8, 2026 at 10:26 pm

    A couple of blog posts deal with this issue: (here and here)

    • It turns out that the log4net TraceAppender converts all log messages
      to Trace.Write messages and that the DiagnosticMonitorTraceListener converts all Trace.Write messages to verbose.

    The answer in my case was to use Pete McEvoy’s solution and extend the TraceAppender in the following manner:

    using System.Diagnostics;
    using log4net.Appender;
    using log4net.Core;
    namespace XXX.Logging
    {
        public class AzureTraceAppender : TraceAppender
        {
            protected override void Append(LoggingEvent loggingEvent)
            {
                var level = loggingEvent.Level;
                var message = RenderLoggingEvent(loggingEvent);
    
                if (level >= Level.Error)
                  Trace.TraceError(message);
                else if (level >= Level.Warn)
                  Trace.TraceWarning(message);
                else if (level >= Level.Info)
                  Trace.TraceInformation(message);
                else
                  Trace.WriteLine(message);
                if (ImmediateFlush)
                  Trace.Flush();
            }
        }
    }
    

    This extension was then implemented in my App.config:

    <log4net>
        <appender name="AzureTraceAppender" type="XXX.Logging.AzureTraceAppender">
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%logger - %message" />
            </layout>
        </appender>
        <root>
            <level value="ALL" />
            <appender-ref ref="AzureTraceAppender" />
        </root>
    </log4net>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a worker role in Azure which uses Process.Start to kick off a
In my solution,I have one Azure worker role project and a class library(which deals
I have an Azure worker role whose job is to periodically run some code
I have a service hosted in a Worker Role in Azure. Clients connect over
I have an azure website which is named: http://myapp.cloudapp.net Of-course this URL is kind
I already have a hosted service deployment which has 2 worker role instances, I
I have a class library shared between an Azure Worker Role and a ASP.NET
We have a requirement to read an excel sheet from the Azure worker role.
I have a Worker Role which isn´t working on Cloud environment. When I run
I have created a Azure Worker Role Project. Target machine of the project has

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.