I have the following configuration and code, the writer.logentry is not throwing an exception but the file is not created.
Update 1: I changed the listener, I removed eventlog and added flat file log. I still cant see a created .log file
I suppose I am missing something in the configuration?
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="AskAndTrack.log" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, Callstack" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
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})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Flat File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
catch(Exception ex)
{
var logEntry = new LogEntry();
logEntry.Message = ex.Message;
Logger.Write(logEntry);
}
The posted configuration looks OK. Enterprise Library will not throw an exception if an error occurs logging -- it will attempt to log the failure to the errors special source (if configured). You haven't added a Trace Listener for errors but I recommend doing so.
Your issue looks like it is probably permissions. Can you verify that the process has permissions to create a file called AskAndTrack.log? Or perhaps create the file ahead of time or write to a folder where the permissions are explicitly granted (e.g. Everyone Full Control (for testing only!)).
Look to me like you are missing the category and priority, here is my snippet. Ignore the helper methods they just return a category such as your 'General' and a priority such as 'Error'.
if (!Logger.Writer.IsLoggingEnabled()) return;
var logEntry = new LogEntry { Severity = GetTraceEventTypeFromPriority(severity) };
logEntry.Categories.Add(GetLogCategory(app_name, severity)); // CHANGED TO NONE BECAUSE SITECORE SUCKS
logEntry.Priority = (int)severity;
if (!Logger.ShouldLog(logEntry)) return;
logEntry.Message = message;
logEntry.Title = GetLogTitle(RequestDataManager.RequestData.blah, message, severity);
lock (_locker)
{
Logger.Write(logEntry);
}
Related
I'm trying new VisualStudio for Mac (Mono 6.0.0.296) with With Microsoft Enterprise Library 6.0.1304. Unfortunatly im not able to use it since an "NotImplementedException" is raised.
I have been using Enterprise Library for many years but in Visual Studio (Windows Env.) and it is great but when i tried to use the same under mono everything seems not working.
After some search i can see that mscorlib.dll for MONO dows not support WindowsIdentity "User" Property.
mscorlib.dll (4.0.0.0 - MONO)
using System.Runtime.InteropServices;
[MonoTODO ("not implemented")]
[ComVisible (false)]
public SecurityIdentifier User {
get {
throw new NotImplementedException ();
}
}
Application:
public static void Main (string [] args)
{
LogWriter logWriter = new LogWriterFactory ().Create ();
Logger.SetLogWriter (logWriter, false);
logWriter.Write ("Application is working", "General", 5, 2000, TraceEventType.Information);
}
App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name=""
tracingEnabled="false"
defaultCategory="General"
logWarningsWhenNoCategoriesMatch="false">
<listeners>
<add name="Rolling Flat File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="RollingFlatFile.log"
footer="----------------------------------"
formatter="Text Formatter"
header="" rollInterval="Day"
traceOutputOptions="DateTime, Timestamp"
filter="All" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp(local)}{newline}
Message: {message}{newline}
Category: {category}{newline}
Priority: {priority}{newline}
Severity: {severity}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" autoFlush="true" name="General">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Rolling Flat File Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
</configuration>
Error tracked into the file:
Timestamp: 12/07/2019 16:36:11
Message: Processing of the message failed. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks.
Summary for Enterprise Library Distributor Service:
-->
Message:
Timestamp: 12/07/2019 14:36:11
Message: Application is working
Category: General
Priority: 5
EventId: 2000
Severity: Information
Title:
Machine: MacBook-Pro-di-John
App Domain: F.B.Library.exe
ProcessId: Unable to read intrinsic property. Error message: GetCurrentProcessId
Process Name: Unable to read intrinsic property. Error message: GetModuleHandle
Thread Name:
Win32 ThreadId:Unable to read intrinsic property. Error message: GetCurrentThreadId
Extended Properties:
--> MachineName: MacBook-Pro-di-John
--> TimeStamp: 12/07/2019 14:36:11
--> FullName: Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
--> AppDomainName: F.B.Library.exe
--> WindowsIdentity: jfk
Exception Information Details:
Exception Type: System.NotImplementedException
Message: The method or operation is not implemented.
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Security.Principal.WindowsIdentity GetCurrent(Boolean)
HelpLink: NULL
Source: mscorlib
HResult: -2147467263
StackTrace Information Details:
at System.Security.Principal.WindowsIdentity.GetCurrent (System.Boolean ifImpersonating) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-02/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Security.Principal/WindowsIdentity.cs:165
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.RevertExistingImpersonation () [0x0000f] in :0
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.ProcessLog (Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry log, System.Diagnostics.TraceEventCache traceEventCache) [0x00000] in :0
at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter+<>c__DisplayClass13.b__12 () [0x0007f] in :0
From The log, you can clearly see that System.Security.Principal.WindowsIdentity.GetCurrent breaks the rule...
Could you Kindly help me on this?
Did anyone try to use Enterprise Library with Mono on MacOS?
Is somewhere present a workaround?
Thanks a lot for your help and time.
Regards,
finally i have managed such situation.
First of all, thanks to all comments, those helped me lot of with resolution.
Basically, i had to change a part of MEL 6 code and then i could use it without issue.
As previously suggested by #SushiHangover, i took MEL 6 source code and i started to analyze... i have fould a part of the code that was calling SecurityIdentifier User inside mscorlib.dll
What i did is:
- download MEL 6 source code
- open it with Visual Studio for MAC
- delete all Test projects and files not supported by the engine
- compile till everything is fine
Once you have your prj compiled, find and comment "Impersonation" section of the below section:
private void ProcessLog(LogEntry log, TraceEventCache traceEventCache)
{
// revert any outstanding impersonation
//using (RevertExistingImpersonation())
//{
var items = new ContextItems();
items.ProcessContextItems(log);
var matchingTraceSources = GetMatchingTraceSources(log);
var traceListenerFilter = new TraceListenerFilter();
foreach (LogSource traceSource in matchingTraceSources)
{
traceSource.TraceData(log.Severity, log.EventId, log, traceListenerFilter, traceEventCache, ReportExceptionDuringTracing);
}
//}
}
Code Sample Image Link
After that, recompile, use compiled dll into your own project and it will finally work.
If you have any further question or dubt, please let me know and i will be happy to reply.
Have a great working day,
Regards,
Florin
I am using Visual Studio 2013, the web server is running .NET 4, and I am getting a error on a web form on the live server, that works fine running on localhost.
It is currently emailing errors when I debug my web application through localhost and I would like it to send me errors when it is live (and if possible, on my localhost as well). It used to send me errors from the production server but when I started debugging, it changed some settings and now it doesn't anymore.
I am assuming that the problem is a setting somewhere, can anyone give some general ideas on where to look for the problem? Here is some code from my web.config for exception handling, is there some other code that could help clarify the problem?
<loggingConfiguration name="Logging Application Block" tracingEnabled="true" defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add toAddress="cynthiat#myurl.com" fromAddress="sysadmin#myurl.com" subjectLineStarter="" subjectLineEnder="" smtpServer="###.###.###.###" smtpPort="##" formatter="Text Formatter" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.EmailTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.EmailTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" name="Email TraceListener" />
<add source="Enterprise Library Logging" formatter="Text Formatter" log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds5" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" name="Formatted EventLog TraceListener" />
</listeners>
<formatters>
<add template="Extended Properties: {dictionary({key} - {value}
)}
Message: {message}
Timestamp: {timestamp}
Severity: {severity}
Machine: {machine}
Process Id: {processId}
Process Name: {processName}
Win32 Thread Id: {win32ThreadId}
Thread Name: {threadName}
" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events">
<listeners>
<add name="Email TraceListener" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
<add name="Global Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=f890890fsfds" name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
We can't help too much with your specific question without seeing more of your config file(s) and/or error handling code that sends e-mail notifications. However, another solution to your problem may be an error hanndling/logging/notification framework, such as:
ELMAH
ELMAH: Error Logging Modules and Handlers for ASP.NET (and MVC too!)
NuGet package - https://www.nuget.org/packages/elmah/
Source - https://code.google.com/p/elmah/
Cloud logging - https://elmah.io
Enterprise Library
Microsoft Enterprise Library
Logging application block
Exception Handling application block
I want to log my application with Enterprise Library 6 in a SQL DB.
I launched the SQL scripts to create SQL things, and I decided to put Logger in Class Library.
Here is the code i've done in order to make the POC:
Portable Class content:
public static void LogToDatabase()
{
try
{
//Bootstrapping logging
DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
Logger.SetLogWriter(logWriterFactory.Create());
if (Logger.IsLoggingEnabled())
{
LogEntry log = GetLogEntry();
log.Categories.Add("General"); // name of Categorie in EntLib Config editor
log.Priority = 5;
log.Severity = System.Diagnostics.TraceEventType.Information;
log.Message = "Hello dude, from Logger";
Logger.Write(log);
}
}
catch (Exception ex)
{
}
}
private static LogEntry GetLogEntry()
{
LogEntry log = new LogEntry();
log.TimeStamp = DateTime.Now;
log.Title = "TANOLIS";
log.Priority = 5; // default priority
log.Severity = System.Diagnostics.TraceEventType.Verbose; // default severity
log.MachineName = "MachineName";//HttpContext.Current.Server.MachineName;
log.ProcessId = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
return log;
}
And this is the Config string I've done in the Unit test (where I launch the LogToDatabase()) :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
databaseInstanceName="DB_Belval" writeLogStoredProcName="WriteLog"
addCategoryStoredProcName="AddCategory" formatter="DB Command Formatter" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
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})}"
name="DB Command Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Database Trace Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Database Trace Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<dataConfiguration defaultDatabase="MY-DB" />
<connectionStrings>
<add name="DB_Belval" connectionString="Data Source=server;Initial Catalog=catalog;Persist Security Info=True;User=username;Password=pwd"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
The error comes in this line:
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);
and is
Invalid TraceListenerData type in configuration 'listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"'.
Thanks to help me :-)
I finally found the solution, I included using Microsoft.Practices.EnterpriseLibrary.Logging.Database; to the caller (the UnitTest)
Question is resolved but it still not working... so warning, don't take the whole code :-)
For the following "project" I am getting a very annoying and inexplicable error when resolving Unity for DI.
InvalidOperationException - The type LogWriter cannot be constructed.
You must configure the container to supply this value.
?ex.Message; "Resolution of the dependency failed, type =
\"WindowsFormsApplication1.Performance\", name =
\"(none)\".\r\nException occurred while: while resolving.\r\nException
is: InvalidOperationException - The type LogWriter cannot be
constructed. You must configure the container to supply this
value.\r\n-----------------------------------------------\r\nAt the
time of the exception, the container was:\r\n\r\n Resolving
WindowsFormsApplication1.Performance,(none)\r\n Resolving parameter
\"lw\" of constructor
WindowsFormsApplication1.Performance(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter
lw,
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionManager
em)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)\r\n"
?ex.StackTrace; " at
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
existing, String name, IEnumerable1 resolverOverrides) in
e:\\Builds\\Unity\\UnityTemp\\Compile\\Unity\\Unity\\Src\\UnityContainer.cs:line
515\r\n at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type
t, String name, IEnumerable1 resolverOverrides) in
e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line
485\r\n at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t,
String name, ResolverOverride[] resolverOverrides) in
e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line
173\r\n at
Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer
container, ResolverOverride[] overrides) in
e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainerExtensions.cs:line
504\r\n at WindowsFormsApplication1.Form1.OnLoad(EventArgs e) in
D:\Devzone\Tasking\WindowsFormsApplication1\Form1.cs:line 33"
In a form:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
IUnityContainer container = new UnityContainer();
Performance p = container.Resolve<Performance>();
}
catch (Exception ex)
{
}
}
Dependency class:
public class Performance
{
public Performance(LogWriter lw, ExceptionManager em)
{
}
}
Configuration File:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
<add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
source="Enterprise Library Logging" formatter="Text Formatter"
log="" machineName="." traceOutputOptions="None" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
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})}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="Event Log Listener" />
</listeners>
</add>
<add switchValue="All" name="Category2" />
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Event Log Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
<exceptionPolicies>
<add name="Policy">
<exceptionTypes>
<add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" />
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
</configuration>
You need to add the Enterprise Library extension to your container. Without it, the container doesn't read the config file and therefore doesn't know how to create Entlib objects, like the LogWriter.
Activation error occured while trying to get instance of type LogWriter, key ""
check your config file it must have correct default 'loggingConfiguration' section
In order for Unity to construct your Performance class, it needs to know how to construct the implementation of ILogWriter.
I cannot see anywhere in your code where you tell Unity what class to create for the ILogWriter interface, so I suspect you may need to add this.
Try this:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
try
{
IUnityContainer container = new UnityContainer();
container.RegisterType<ILogWriter, LogWriter>();
container.RegisterType<ExceptionManager>();
container.RegisterType<Performance>(new InjectionConstructor(typeof(ILogWriter), typeof(ExceptionManager));
Performance p = container.Resolve<Performance>();
}
catch (Exception ex)
{
}
}
LogWriter does not have an empty constructor or a constructor with all concrete types parameters: LogWriter Constructor.
So Unity fails in building it and as it says, it will need your help by configuring the container to provide an implementation.
As a confirmation, ExceptionManager will probably be resolved ok, since it has only one constructor, parameterless as well :)
I am using Logging Application block with C#.Net 2.0. My code is logging the error information to a flat file. I have set all required configuration in web.config like listeners, formatters and categories, etc as described in msdn and it is working fine.
But the problem is, I cannot put more than 50 characters in le.Message property. In my case, the stack trace is more than 500 charactors long which I want to log into the flat file when error occurs.
Is there any limit on number of charactors we can put inside Message Property of LogEntry object? or is there any other way to log the stack trace into logger flat file?
Here is the simple code.
LogEntry le = new LogEntry();
le.Categories.Add("ErrorsToEventLog");
le.Categories.Add("ErrorsToLogFile");
le.Title = "Error message";
le.TimeStamp = System.DateTime.Now;
le.Severity = System.Diagnostics.TraceEventType.Error;
le.Message = "<text of error's stack trace>";
Logger.write(le);
configuration settings
<configSections>
<section name="loggingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=null" />
<section name="dataConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=null" />
</configSections>
Here is the formatter I used,
<formatters>
<add template="Timestamp: {timestamp} Message: {message}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0,
Culture=neutral, PublicKeyToken=null" name="Text Formatter" />
</formatters>
And here is the listener,
<add fileName="Logs/ErrorLog_{Date}.log"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.
CustomTraceListenerData,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=null" traceOutputOptions="None"
type="EnterpriseLibrary.Logging.Extensions.RollingFlatFileTraceListener,
EnterpriseLibrary.Logging.Extensions, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" name="Custom TraceListener" initializeData="" />
Categories
<categorySources>
<add switchValue="All" name="ErrorsToEventLog">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
<add switchValue="All" name="ErrorsToLogFile">
<listeners>
<add name="Custom TraceListener" />
</listeners>
</add>
</categorySources>
To my knowledge, there is no such limit for log message. How do you set the stack trace to the message?
Assuming your analysis is correct (it isn't convenient for me to double-check right now), have you considered creating a subclass for LogEntry that doesn't have the limits that you're running up against?