Hello,
I’m trying to make the .NET LINQ SQL logging feature to work but i can’t. I use the sample code presented in the What’s New page for version 3.
I need to use the feature in a WCF architecture where all clients get database access through Service functions. In each function, i create and dispose a DataContext object.
e.g.
public int? ValidateCredentials(string UserName, string Password, out List AllPermissions,
out List UserPermissions, out User user)
{
AllPermissions = null;
UserPermissions = null;
user = null;
ExrayDataContext dataContext = null;
try
{
dataContext = new ExrayDataContext(DBConnectionString);
dataContext.ObjectTrackingEnabled = false;
AllPermissions = new List<string>();
UserPermissions = new List<string>();
User objUser =
User.ClientsService_ValidateCredentials(dataContext, UserName,
Convert.ToBase64String(Encoding.ASCII.GetBytes(Password))).SingleOrDefault();
if (objUser == null) return 1;
if (SiAuto.Si.GetSession(UserName) == null) SiAuto.Si.AddSession(UserName, true);
dataContext.Log = new SmartInspectLinqToSqlAdapter(SiAuto.Si.GetSession(UserName))
{TitleLimit = 0, TitlePrefix = "ValidateCredentials"};
List<Permission> objPermissions = Permission.ClientsService_ValidateCredentials(dataContext, objUser.Id).Distinct().ToList();
foreach (Permission permission in objPermissions)
{
UserPermissions.Add(permission.ObjectId + "_" + permission.ObjectType + "_" +
permission.Type.ToUpper() + (permission.Path == null ? "" : "^" + permission.Path));
}
foreach (Permission permission in dataContext.Permissions)
{
AllPermissions.Add(permission.ObjectId + "_" + permission.ObjectType + "_" +
permission.Type.ToUpper() + (permission.Path == null ? "" : "^" + permission.Path));
}
user = objUser;
return 0;
}
catch (Exception exc)
{
HandleException(UserName, exc);
return null;
}
finally
{
if (dataContext != null) dataContext.Dispose();
}
}
Do i have to do something more? What is the purpose of Write & WriteLine methods? Aren’t all the LINQ queries automatically written to log?
I use file logging. Even if i can get the LINQ SQL logging to work, to what level are these statements logged? I really need to enable them only for Debug level.