1
Vote

5.0 Enterprise Library failing to log under visual studio 2015

description

I have some code that had been working under both Visual Studio 2012, and later we upgraded the project to Visual Studio 2013 and it was still working fine. Today I tried compiling it under Visual Studio 2015, it compiled fine, no warnings or errors. But when we try to log an error, the function seems to be taking a long time and nothing is generated. Here is the configuration block:

private static void LoggingInitialization()
    {
        var configBuilder = new ConfigurationSourceBuilder();

        configBuilder.ConfigureLogging().WithOptions
            .DoNotRevertImpersonation()
            .LogToCategoryNamed("Trace")
                .WithOptions.SetAsDefaultCategory()
                .SendTo
                    .FlatFile("Flatfile Trace Listener")
                    .FormatWith(
                        new FormatterBuilder()
                            .TextFormatterNamed("File Formatter")
                            .UsingTemplate("Timestamp: {timestamp}{newline}Message: {message}{newline}Log Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title: {title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId: {win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}")
                        )
                    .ToFile(@"c:\test.log")
                .SendTo
                    .EventLog("Event Log Listener")
                    .FormatWith(
                        new FormatterBuilder()
                            .TextFormatterNamed("Text Formatter")
                            .UsingTemplate("Timestamp: {timestamp}{newline}Message: {message}{newline}Log Category: {category}{newline}Priority: {priority}{newline}EventId: {eventid}{newline}Severity: {severity}{newline}Title: {title}{newline}Machine: {localMachine}{newline}App Domain: {localAppDomain}{newline}ProcessId: {localProcessId}{newline}Process Name: {localProcessName}{newline}Thread Name: {threadName}{newline}Win32 ThreadId: {win32ThreadId}{newline}Extended Properties: {dictionary({key} - {value}{newline})}")
                        )
                    .ToLog("Application")
                .SendTo
                    .Email("Email Trace Listener")
                    .To(Global.ErrorEmailTo)
                    .From(Global.ErrorEmailFrom)
                    .WithSubjectStart(String.Format("{0} {1} Application", Global.WorkingEnvironment, Global.ApplicationName))
                    .WithSubjectEnd("")
                    .UsingSmtpServer(Global.SMTPServer)
                    .UsingSmtpServerPort(Global.SMTPPort)
                    .Unauthenticated()
                    .FormatWithSharedFormatter("Text Formatter");

        configBuilder.ConfigureExceptionHandling()
            .GivenPolicyWithName(Global.ApplicationLayerPolicy)
            .ForExceptionType<System.Exception>()
            .LogToCategory("Trace")
            .WithSeverity(TraceEventType.Error)
            .UsingEventId(100)
            .ThenNotifyRethrow();

        var configSource = new DictionaryConfigurationSource();
        configBuilder.UpdateConfigurationWithReplace(configSource);
        EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
Normally the code is called from:
try
{
..some code here
}
catch (Exception ex)
        {
            ExceptionPolicy.HandleException(ex, Global.ApplicationLayerPolicy);
        }

comments