- clog_01_07.zip
- bin
- Debug
- DanielVaughan.Core.dll
- DanielVaughan.Core.pdb
- DanielVaughan.Logging.dll
- DanielVaughan.Logging.EnterpriseLibraryLogStrategy.dll
- DanielVaughan.Logging.EnterpriseLibraryLogStrategy.pdb
- DanielVaughan.Logging.Log4NetLogStrategy.dll
- DanielVaughan.Logging.Log4NetLogStrategy.pdb
- DanielVaughan.Logging.pdb
- Release
- DanielVaughan.Core.dll
- DanielVaughan.Core.pdb
- DanielVaughan.Logging.dll
- DanielVaughan.Logging.EnterpriseLibraryLogStrategy.dll
- DanielVaughan.Logging.EnterpriseLibraryLogStrategy.pdb
- DanielVaughan.Logging.Log4NetLogStrategy.dll
- DanielVaughan.Logging.Log4NetLogStrategy.pdb
- DanielVaughan.Logging.pdb
- Silverlight
- DanielVaughan.Logging.Silverlight.dll
- DanielVaughan.Logging.Silverlight.pdb
- DanielVaughan.Logging.Silverlight.UI.dll
- DanielVaughan.Logging.Silverlight.UI.pdb
- Clog
- Source
- Documentation
- Libraries
- EnterpriseLibrary
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Data.dll
- Microsoft.Practices.EnterpriseLibrary.Logging.dll
- Microsoft.Practices.ObjectBuilder.dll
- Log4Net
- Open Silverlight Edition.bat
- Open WPF Edition.bat
- Resources
- Images
- ClogLogo.gif
- LogoLarge.jpg
- Schemas
- SilverlightEdition
- Documentation
- Source
- WpfEdition
- Source
- clog.zip
|
/*
<File>
<Copyright>Copyright © 2007, Daniel Vaughan. All rights reserved.</Copyright>
<License see="prj:///Documentation/License.txt"/>
<Owner Name="Daniel Vaughan" Email="dbvaughan@gmail.com"/>
<CreationDate>2007/11/27 12:44</CreationDate>
<LastSubmissionDate>$Date: $</LastSubmissionDate>
<Version>$Revision: $</Version>
</File>
*/
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Security;
namespace DanielVaughan.Logging.Filters
{
/// <summary>
/// Restricts a log entry based on the current
/// <see cref="Environment.UserName"/> value,
/// as specified in the comma delimited <em>users</em> attribute
/// of the filter element.
/// </summary>
class EnvironmentUserFilter : FilterBase
{
readonly List<string> users = new List<string>();
/// <summary>
/// Gets or sets a set of user names to be used by an <see cref="IFilter"/>.
/// </summary>
/// <value>The users.</value>
public IEnumerable<string> Users
{
get
{
return users;
}
}
public EnvironmentUserFilter()
{
Init += EnvironmentUserFilter_Init;
}
void EnvironmentUserFilter_Init(object sender, FilterInitEventArgs e)
{
ArgumentValidator.AssertNotNull(e, "e");
ArgumentValidator.AssertNotNull(e.ConfigurationElement, "e.ConfigurationElement");
/* Reset state. */
users.Clear();
/* TODO: put in util.*/
var usersAttribute = e.ConfigurationElement.Attributes["Users"];
if (usersAttribute == null)
{
throw new ClientLoggingException("Users attribute does not exists."); /* TODO: Make localizable resource. */
}
try
{
string usersValue = usersAttribute.Value;
var userValues = usersValue.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
users.AddRange(userValues);
}
catch (Exception ex)
{
throw new ClientLoggingException("Users attribute is invalid. Should be a comma seperated list of names.", ex); /* TODO: Make localizable resource. */
}
if (Action == FilterAction.Default)
{
Action = FilterAction.Allow;
}
if (Action != FilterAction.Allow && Action != FilterAction.Deny)
{
throw new ConfigurationErrorsException(InvalidActionMessage);
}
}
public override bool IsValid(LogEntryOrigin origin, IClientInfo info)
{
string userName = info.UserName;
foreach (string name in users)
{
if (userName != name)
{
continue;
}
if (Action == FilterAction.Deny)
{
return false;
}
if (Action == FilterAction.Allow)
{
return true;
}
}
return Action != FilterAction.Allow;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Daniel is a former senior engineer in Technology and Research at the Office of the CTO at Microsoft, working on next generation systems.
Previously Daniel was a nine-time Microsoft MVP and co-founder of
Outcoder, a Swiss software and consulting company.
Daniel is the author of Windows Phone 8 Unleashed and Windows Phone 7.5 Unleashed, both published by SAMS.
Daniel is the developer behind several acclaimed mobile apps including
Surfy Browser for Android and Windows Phone. Daniel is the creator of a number of popular open-source projects, most notably
Codon.
Would you like Daniel to bring value to your organisation?
Please contact
Blog |
Twitter
Xamarin Experts
Windows 10 Experts